-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.java
More file actions
executable file
·84 lines (74 loc) · 1.85 KB
/
Button.java
File metadata and controls
executable file
·84 lines (74 loc) · 1.85 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
73
74
75
76
77
78
79
80
81
82
83
84
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Button Superclass
*
* @author Jimmy, Adrian, Daniel
* @version April 24, 2024
*/
public class Button extends Actor {
private boolean ifDiscbetion = false;
private String discbetion;
private GreenfootImage image;
private GreenfootImage imageSelected;
protected boolean toggleState = false;
private MouseInfo m = Greenfoot.getMouseInfo();
public Button() {}
/**
* Constructor for Button
*
* @param path Location of file
* @param scalePercent Image scale percentage
*/
public Button(String path, int scalePercent) {
image = new GreenfootImage(path);
double width = image.getWidth() * scalePercent / 100;
double height = image.getHeight() * scalePercent / 100;
image.scale((int) width, (int) height);
setImage(image);
}
public Button(boolean Discbetion) {
this.ifDiscbetion = Discbetion;
}
/**
* Act - do whatever the Button wants to do. This method is called whenever the 'Act' or 'Run'
* button gets pressed in the environment.
*/
public void act() {}
/**
* Checks if clicked
*
* @return boolean
*/
public boolean cheakDis() {
return ifDiscbetion;
}
/**
* Checks if the button was clicked
*
* @return boolean True if clicked, false if not clicked
*/
public boolean checkClicked() {
if (Greenfoot.mouseClicked(this)) {
return true;
}
return false;
}
/** Toggle the state of the button */
public void toggle() {
if (toggleState) {
toggleState = false;
} else {
toggleState = true;
}
}
public boolean openDis(boolean ifDiscbetion) {
if (ifDiscbetion && Greenfoot.mouseClicked(this) && m.getButton() == 3) {
return true;
}
return false;
}
/** Getter method */
public String getDis() {
return discbetion;
}
}