Skip to content

Commit 052216c

Browse files
committed
Commit: 1.1
1 parent bdb46b7 commit 052216c

File tree

5 files changed

+235
-109
lines changed

5 files changed

+235
-109
lines changed

src/processing/ProcessingTest.java

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package processing;
22

33
import processing.core.PApplet;
4+
import processing.graphics.Button;
5+
import processing.graphics.TextBox;
46
import processing.tree.BinarySearchTree;
57

68
public class ProcessingTest extends PApplet {
@@ -10,30 +12,79 @@ public static void main(String... args) {
1012
PApplet.runSketch(processingArgs, processingTest);
1113
}
1214

13-
BinarySearchTree<Integer> binarySearchTree = new BinarySearchTree<>();
15+
PApplet pApplet = this;
1416

15-
Button enterButton = new Button(this);
16-
Button resetButton = new Button(this);
17-
Button quitButton = new Button(this);
18-
TextBox textBox = new TextBox(this);
17+
BinarySearchTree<Integer> tree = new BinarySearchTree<>(pApplet);
18+
19+
Button enterButton = new Button(pApplet) {
20+
21+
@Override
22+
public void setOnAction() {
23+
if (textBox.getText().length() != 0) {
24+
tree.add(Integer.valueOf(textBox.getText()));
25+
26+
textBox.setText("");
27+
textBox.render();
28+
29+
System.out.println("AWIT");
30+
}
31+
}
32+
};
33+
34+
Button resetButton = new Button(pApplet) {
35+
36+
@Override
37+
public void setOnAction() {
38+
BinarySearchTree<Integer> newTree = new BinarySearchTree<>(pApplet);
39+
40+
background(210);
41+
42+
tree = newTree;
43+
textBox.setText("");
44+
}
45+
46+
};
47+
Button quitButton = new Button(pApplet) {
48+
49+
@Override
50+
public void setOnAction() {
51+
exit();
52+
}
53+
54+
};
55+
56+
TextBox textBox = new TextBox(pApplet) {
57+
58+
@Override
59+
public void setOnPressedKeyAction(char key, int keyCode) {
60+
61+
if (textBox.keyPressed(key, keyCode)) {
62+
tree.add(Integer.valueOf(textBox.getText()));
63+
64+
textBox.setText("");
65+
textBox.render();
66+
}
67+
68+
}
69+
};
1970

2071
public void settings() {
2172
size(1000,800);
2273
}
2374

2475
public void setup() {
2576
background(210);
77+
textSize(14);
2678

27-
textBox.setId("InputGetterId");
2879
textBox.setWidth(245);
2980
textBox.setHeight(20);
3081
textBox.setX((width / 2) - (textBox.getWidth() / 2));
3182
textBox.setY(height - textBox.getHeight());
3283
textBox.setPadding(0, 0, 40, 0);
3384
textBox.setBackgroundColor(255, 255, 255);
85+
textBox.setDisableLetters(true);
3486

3587
enterButton.setText("Insert");
36-
enterButton.setId("enterId");
3788
enterButton.setWidth(75);
3889
enterButton.setHeight(20);
3990
enterButton.setX((width / 2) - (textBox.getWidth() / 2));
@@ -42,7 +93,6 @@ public void setup() {
4293
enterButton.setBackgroundColor(255, 255, 255);
4394

4495
resetButton.setText("Reset");
45-
resetButton.setId("resetId");
4696
resetButton.setWidth(75);
4797
resetButton.setHeight(20);
4898
resetButton.setX((width / 2) - (textBox.getWidth() / 2) + enterButton.getWidth());
@@ -51,7 +101,6 @@ public void setup() {
51101
resetButton.setBackgroundColor(255, 255, 255);
52102

53103
quitButton.setText("Quit");
54-
quitButton.setId("quitId");
55104
quitButton.setWidth(75);
56105
quitButton.setHeight(20);
57106
quitButton.setX((width / 2) - (textBox.getWidth() / 2) + enterButton.getWidth() + resetButton.getWidth());
@@ -63,9 +112,18 @@ public void setup() {
63112
enterButton.render();
64113
resetButton.render();
65114
quitButton.render();
115+
// createTitle();
66116
}
67117

68118
public void draw() {
119+
// tree.add(2);
120+
// tree.add(3);
121+
// tree.add(1);
122+
// tree.add(6);
123+
// tree.add(10);
124+
// tree.add(5);
125+
// tree.add(7);
126+
// tree.add(4);
69127
}
70128

71129
void InintLayout() {
@@ -75,10 +133,15 @@ void InintLayout() {
75133
public void mousePressed() {
76134
textBox.pressed(mouseX, mouseY);
77135

136+
enterButton.pressed(mouseX, mouseY);
137+
138+
quitButton.pressed(mouseX, mouseY);
139+
140+
resetButton.pressed(mouseX, mouseY);
78141
}
79142

80143
public void keyPressed() {
81-
textBox.keyPressed(key, keyCode);
144+
textBox.setOnPressedKeyAction(key, keyCode);
82145
}
83146

84147
public void mouseMoved() {
@@ -88,5 +151,14 @@ public void mouseMoved() {
88151
resetButton.cursorTouched();
89152
quitButton.cursorTouched();
90153
textBox.cursorTouched();
154+
155+
createTitle();
156+
}
157+
158+
public void createTitle() {
159+
String title = "Binary Search Tree";
160+
textSize(40);
161+
text(title, (width / 2) - title.length() , 20);
162+
textSize(14);
91163
}
92164
}
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
package processing;
1+
package processing.graphics;
22

33
import processing.core.PVector;
44
import processing.core.PApplet;
55

6-
public class Button extends PApplet {
6+
public class Button extends Functions {
77
public Button(PApplet pApplet) {
8-
this.text = text;
8+
this.text = "";
99
this.width = 10;
1010
this.height = 10;
11-
this.backgroundColor = color(255, 255, 255);
12-
this.backgroundSelected = color(150);
13-
this.borderColor = color(0, 0, 0);
11+
this.backgroundColor = pApplet.color(255, 255, 255);
12+
this.backgroundSelected = pApplet.color(150);
13+
this.borderColor = pApplet.color(0, 0, 0);
1414
this.pos = new PVector(0, 0);
1515
this.pApplet = pApplet;
1616
}
1717

1818
private PApplet pApplet;
1919
private PVector pos;
2020
private String text;
21-
private String id;
2221
private float width;
2322
private float height;
2423
private int backgroundColor;
2524
private int borderColor;
2625
private int backgroundSelected;
27-
28-
boolean pressed;
29-
boolean clicked;
26+
private boolean selected;
3027

3128
public void setText(String text) {
3229
this.text = text;
@@ -36,14 +33,6 @@ public String getText() {
3633
return this.text;
3734
}
3835

39-
public void setId(String id) {
40-
this.id = id;
41-
}
42-
43-
public String getId() {
44-
return this.id;
45-
}
46-
4736
public void setWidth(float width) {
4837
this.width = width;
4938
}
@@ -82,11 +71,11 @@ public float getY() {
8271
}
8372

8473
public void setBackgroundColor(int r, int g, int b) {
85-
backgroundColor = color(r, g, b);
74+
backgroundColor = pApplet.color(r, g, b);
8675
}
8776

8877
public void setBorderColor(int r, int g, int b) {
89-
borderColor = color(r, g, b);
78+
borderColor = pApplet.color(r, g, b);
9079
}
9180

9281
public void render() {
@@ -102,8 +91,8 @@ public void render() {
10291

10392
pApplet.rect(pos.x, pos.y, width, height);
10493

105-
pApplet.textAlign(CENTER, CENTER);
10694
pApplet.fill(0);
95+
pApplet.textAlign(pApplet.CENTER, pApplet.CENTER);
10796
pApplet.text(text, pos.x + (width / 2), pos.y + (height / 2));
10897

10998
}
@@ -129,10 +118,19 @@ private boolean hovering() {
129118
}
130119

131120
private void mouseOver() {
132-
pApplet.cursor(HAND);
121+
pApplet.cursor(pApplet.HAND);
122+
}
123+
124+
private boolean overBox(float x, float y) {
125+
return x >= pos.x && x <= (pos.x + this.width)
126+
&& y >= pos.y && y <= (pos.y + this.height);
133127
}
134128

135-
public void setOnClickedAction() {
129+
public void pressed(float x, float y) {
130+
selected = overBox(x, y);
136131

137-
};
132+
if (selected) {
133+
setOnAction();
134+
}
135+
}
138136
}

0 commit comments

Comments
 (0)