Last change
on this file since a5b4186 was a5b4186, checked in by dportnoy <dmp1488@…>, 17 years ago |
[svn r36] Renamed remotely
|
-
Property mode
set to
100644
|
File size:
930 bytes
|
Line | |
---|
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.