Rev | Line | |
---|
[55522be] | 1 | package gamegui;
|
---|
| 2 |
|
---|
| 3 | import java.awt.*;
|
---|
| 4 |
|
---|
| 5 | public class Button extends Member
|
---|
| 6 | {
|
---|
| 7 | private String text;
|
---|
| 8 | private Font font;
|
---|
| 9 |
|
---|
| 10 | public Button(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont)
|
---|
| 11 | {
|
---|
| 12 | super(newName, newX, newY, newWidth, newHeight);
|
---|
| 13 |
|
---|
| 14 | text = newText;
|
---|
| 15 | font = newFont;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | public void draw(Graphics g)
|
---|
| 19 | {
|
---|
| 20 | FontMetrics metrics = g.getFontMetrics(font);
|
---|
| 21 |
|
---|
| 22 | g.setColor(Color.red);
|
---|
| 23 | g.drawRect(getX(), getY(), getWidth(), getHeight());
|
---|
| 24 |
|
---|
| 25 | g.setColor(Color.green);
|
---|
| 26 | g.setFont(font);
|
---|
| 27 | g.drawString(text, getX() + (getWidth() - metrics.stringWidth(text))/2, getY() + (getHeight() + metrics.getHeight())/2 - 2);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public boolean isClicked(int xCoord, int yCoord)
|
---|
| 31 | {
|
---|
| 32 | if(xCoord < getX() || getX() + getWidth() < xCoord)
|
---|
| 33 | return false;
|
---|
| 34 | if(yCoord < getY() || getY() + getHeight() < yCoord)
|
---|
| 35 | return false;
|
---|
| 36 |
|
---|
| 37 | return true;
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.