-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.java
More file actions
66 lines (59 loc) · 1.86 KB
/
Button.java
File metadata and controls
66 lines (59 loc) · 1.86 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
/*
* Button class will define a rectangle that will change color if mouse is in it
*/
import processing.core.PApplet; //included the PApplet import
public class Button {
/////////////////////////////fields////////////////////////////
//x position of button
private int xLocation;
//y position of button
private int yLocation;
//width of button
private int Width;
//height of button
private int Height;
//boolean variable asking if the mouse is in the button
private boolean inButton;
//String variable labeling the button
private String label;
/////////////////////////////constructors/////////////////////
/**
*A constructor that takes the x, y, w, and h variables
*PApplet a passed from main tab
*
*/
public Button(int xLocation, int yLocation, int Width, int Height, String label, PApplet p) {
this.xLocation=xLocation;
this.yLocation=yLocation;
this.Width=Width;
this.Height=Height;
//If mouse is in the button, the boolean variable is true
if (p.mouseX>xLocation-Width/2 && p.mouseX<xLocation+Width/2 && p.mouseY>yLocation-Height/2 && p.mouseY<yLocation+Height/2) {
this.inButton=true;
}
this.label=label;
}
//////////////////////////Methods//////////////////////////
/**
* A method that draws the button
*@param a the PApplet object passed from main tab
*/
public void drawButton(PApplet p) {
p.rectMode(p.CENTER);
p.stroke(0);
p.strokeWeight(1);
p.fill(255);
if (this.inButton) {
p.fill(0, 255, 0);
}
p.rect(this.xLocation, this.yLocation, this.Width, this.Height);
p.textSize(16);
p.fill(0);
p.textAlign(p.CENTER, p.CENTER);
p.text(this.label, this.xLocation, this.yLocation);
}
//get method for inButton
public boolean getinButton() {
return this.inButton;
}
}