source: lost-haven/gamegui/RadioButton.java@ 3d64884

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