source: lost-haven/gamegui/RadioGroup.java@ a5b4186

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: 1.9 KB
Line 
1package gamegui;
2
3import java.awt.*;
4import java.awt.event.*;
5import java.util.*;
6
7
8public class RadioGroup extends Member
9{
10 private ArrayList<RadioButton> buttons;
11 private RadioButton selected;
12 private String text;
13 private Font font;
14
15 public RadioGroup(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) {
16 super(newName, newX, newY, newWidth, newHeight);
17
18 buttons = new ArrayList<RadioButton>();
19 selected = null;
20 text = newText;
21 font = newFont;
22 }
23
24 public boolean handleEvent(MouseEvent e) {
25 if(selected != null)
26 selected.clear();
27
28 for(int x=0; x < buttons.size(); x++)
29 if(((RadioButton)buttons.get(x)).isClicked(e.getX(), e.getY())) {
30 selected = buttons.get(x);
31 selected.setSelected(true);
32 return true;
33 }
34
35 return false;
36 }
37
38 public void draw(Graphics g)
39 {
40 FontMetrics metrics = g.getFontMetrics(font);
41
42 g.setColor(Color.green);
43 g.setFont(font);
44
45 g.drawString(text, getX() - metrics.stringWidth(text) - 10, getY() + (getHeight() + metrics.getHeight())/2 - 2);
46
47 for(int x=0; x < buttons.size(); x++)
48 ((RadioButton)(buttons.get(x))).draw(g);
49 }
50
51 public void clear()
52 {
53 for(int x=0; x < buttons.size(); x++)
54 ((RadioButton)(buttons.get(x))).clear();
55 }
56
57 public void add(RadioButton aButton) {
58 buttons.add(aButton);
59 }
60
61 public RadioButton getButton(String aName) {
62 for(int x=0; x < buttons.size(); x++)
63 if(buttons.get(x).getName().equals(aName))
64 return (RadioButton)buttons.get(x);
65
66 return null;
67 }
68
69 public String getSelected() {
70 if(selected != null)
71 return selected.getName();
72 else
73 return "None";
74 }
75
76 public void setSelected(String button) {
77 clear();
78
79 for(int x=0; x < buttons.size(); x++)
80 if(buttons.get(x).getName().equals(button))
81 buttons.get(x).setSelected(true);
82 }
83}
Note: See TracBrowser for help on using the repository browser.