Example #1
0
 public static Button makeButton(int x, int y, String text, ClickListener listener) {
   int width = 200, height = 50;
   Rectangle shape = new Rectangle(x - width / 2, y - height / 2, width, height);
   try {
     Image up = new Image(width, height);
     Image down = up.copy();
     up.getGraphics().setColor(Color.blue);
     down.getGraphics().setColor(Color.green);
     for (Image im : new Image[] {up, down}) {
       im.getGraphics().fillRect(0, 0, width, height);
       im.getGraphics().setColor(Color.white);
       im.getGraphics().drawString(text, 0, 0);
       im.getGraphics().flush();
     }
     SimpleButton b = new SimpleButton(shape, up, down, null);
     if (listener != null) {
       b.addListener(listener);
     }
     return b;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
Example #2
0
 public void draw() {
   Image rotated = image.copy();
   if (moving) rotated.setRotation((float) Math.toDegrees(angle));
   rotated.draw(x, y);
 }