source: lost-perception/gamegui/RadioButton.java@ 1c27783

Last change on this file since 1c27783 was ebd3538, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 6 years ago

Initial commit. This codebase for the Lost Perception game was created by decompiling code from a jar file.

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