-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeNodeFunctionButton.java
41 lines (39 loc) · 1.75 KB
/
TreeNodeFunctionButton.java
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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TreeNodeFunctionButton extends JButton {
public TreeNodeFunctionButton(final BstObjPanel bstObjPanel, final JFrame topFrame, final String command) {
super(command);
this.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
bstObjPanel.pause();
String extraWords = "";
String defaultText = "";
while (true) {
String response = JOptionPane.showInputDialog(topFrame,
"Please enter the data of the person you would like to "
+ command
+ "! " + extraWords + "\n(take your time - the visualization was paused)", defaultText);
if (response == null) {
break;
}
Person person;
try {
person = new Person(response.split(","));
} catch (IllegalArgumentException e1) {
extraWords = "(" + e1.getMessage() + ")";
defaultText = "first name, last name, age, state";
continue;
} catch (Exception e2) {
e2.printStackTrace();
continue;
}
bstObjPanel.addTaskToFront(new Task(command.toLowerCase(), person, bstObjPanel.treeShape.root, null));
break;
}
bstObjPanel.unpause();
}
});
}
}