11package processing ;
22
33import processing .core .PApplet ;
4+ import processing .graphics .Button ;
5+ import processing .graphics .TextBox ;
46import processing .tree .BinarySearchTree ;
57
68public 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}
0 commit comments