source: galactic-heroes/gamegui/Button.java@ 7d9c033

Last change on this file since 7d9c033 was 7d9c033, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 years ago

Initial commit, code decompiled from a jar

  • Property mode set to 100644
File size: 1.2 KB
Line 
1package gamegui;
2
3import java.awt.FontMetrics;
4import java.awt.Color;
5import java.awt.Graphics;
6import java.awt.Font;
7
8public class Button extends Member {
9 private String text;
10 private Font font;
11
12 public Button(final String newName, final int newX, final int newY, final int newWidth, final int newHeight, final String newText, final Font newFont) {
13 super(newName, newX, newY, newWidth, newHeight);
14 this.text = new String(newText);
15 this.font = newFont;
16 }
17
18 public void draw(final Graphics g) {
19 final FontMetrics metrics = g.getFontMetrics(this.font);
20 g.setColor(Color.red);
21 g.drawRect(this.getX(), this.getY(), this.getWidth(), this.getHeight());
22 g.setColor(Color.green);
23 g.setFont(this.font);
24 g.drawString(this.text, this.getX() + (this.getWidth() - metrics.stringWidth(this.text)) / 2, this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
25 }
26
27 public boolean isClicked(final int xCoord, final int yCoord) {
28 return xCoord >= this.getX() && this.getX() + this.getWidth() >= xCoord && yCoord >= this.getY() && this.getY() + this.getHeight() >= yCoord;
29 }
30}
Note: See TracBrowser for help on using the repository browser.