source: lost-haven/gamegui/RadioGroup.java@ 8e945fc

Last change on this file since 8e945fc was 8edd04e, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Make the decompiled game code compile successfully

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