This repository was archived by the owner on Nov 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.java
More file actions
72 lines (65 loc) · 1.78 KB
/
Button.java
File metadata and controls
72 lines (65 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.awt.*;
/**
* Abstract class that acts as a rectangular button
*/
public abstract class Button extends Rectangle {
private Mouse mouse;
protected boolean active;
protected String text;
protected Color color;
protected Color hoverColor;
protected Color textColor;
protected int fontSize;
Button(Mouse mouse) {
this.mouse = mouse;
this.active = false;
this.text = "";
this.color = Color.WHITE;
this.hoverColor = Color.WHITE;
this.textColor = Color.BLACK;
this.fontSize = 20;
}
public boolean isActive() {
return this.active;
}
public void setActive(boolean active) {
this.active = active;
}
public void setText(String text) {
this.text = text;
}
public void setColor(Color color) {
this.color = color;
}
public void setHoverColor(Color hoverColor) {
this.hoverColor = hoverColor;
}
public void setTextColor(Color textColor) {
this.textColor = textColor;
}
public void setFontSize(int fontSize) {
this.fontSize = fontSize;
}
public void draw(Graphics g) {
if (!this.active) {
return;
}
((Graphics2D)g).setStroke(new BasicStroke(3));
if (this.contains(this.mouse)) {
g.setColor(this.hoverColor);
}
else {
g.setColor(this.color);
}
g.fillRect(this.x, this.y, this.width, this.height);
g.setColor(this.textColor);
Text.drawCentered(g, this.fontSize, this.text, this);
}
public boolean click(Mouse.Click click) {
if (this.active && this.contains(click)) {
return this.run();
}
return false;
}
public abstract boolean run();
}