source: java-rpg-client/gamegui/RadioButton.java@ 92d1b2a

Last change on this file since 92d1b2a was 55522be, checked in by dportnoy <dmp1488@…>, 17 years ago

[svn r8]

  • Property mode set to 100644
File size: 1.5 KB
Line 
1package gamegui;
2
3import java.awt.*;
4
5public class RadioButton extends Member
6{
7 private String text;
8 private Font font;
9 private boolean textAfter;
10 private boolean selected;
11
12 public RadioButton(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean isTextAfter)
13 {
14 super(newName, newX, newY, newWidth, newHeight);
15
16 text = newText;
17 font = newFont;
18 textAfter = isTextAfter;
19 }
20
21 public void draw(Graphics g)
22 {
23 FontMetrics metrics = g.getFontMetrics(font);
24
25 g.setColor(Color.red);
26 g.drawOval(getX(), getY(), getWidth(), getHeight());
27
28 if(selected)
29 {
30 g.setColor(Color.green);
31 g.fillOval(getX() + 5, getY() + 5, getWidth() - 10, getHeight() - 10);
32 }
33
34 g.setColor(Color.green);
35 g.setFont(font);
36
37 if(textAfter)
38 g.drawString(text, getX() + getWidth() + 7, getY() + (getHeight() + metrics.getHeight())/2 - 2);
39 else
40 g.drawString(text, getX() - metrics.stringWidth(text) - 7, getY() + (getHeight() + metrics.getHeight())/2 - 2);
41 }
42
43 public void clear()
44 {
45 selected = false;
46 }
47
48 public String getLabel() {
49 return text;
50 }
51
52 public boolean isClicked(int xCoord, int yCoord)
53 {
54 double distance = Math.sqrt(Math.pow(getX() + getWidth()/2 - xCoord, 2) + Math.pow(getY() +getHeight()/2 - yCoord, 2));
55
56 return !(distance > getWidth() / 2);
57 }
58
59 public boolean isSelected()
60 {
61 return selected;
62 }
63
64 public void setSelected(boolean isSelected)
65 {
66 selected = isSelected;
67 }
68}
Note: See TracBrowser for help on using the repository browser.