-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckboxDemo.java
More file actions
106 lines (83 loc) · 3.37 KB
/
Copy pathCheckboxDemo.java
File metadata and controls
106 lines (83 loc) · 3.37 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.event.*;
import javafx.geometry.*;
public class CheckboxDemo extends Application {
CheckBox cbSmartphone;
CheckBox cbTablet;
CheckBox cbNotebook;
CheckBox cbDesktop;
Label response;
Label selected;
String computers;
public static void main(String args[]) {
launch(args);
}
public void start(Stage myStage) {
myStage.setTitle("Demonstrate CheckBoxes.");
FlowPane rootNode = new FlowPane(Orientation.VERTICAL, 10, 10);
rootNode.setAlignment(Pos.CENTER);
Scene myScene = new Scene(rootNode, 230, 200);
myStage.setScene(myScene);
Label heading = new Label("What Computers Do You Own?");
response = new Label("");
selected = new Label("");
cbSmartphone = new CheckBox("Smartphone");
cbTablet = new CheckBox("Tablet");
cbNotebook = new CheckBox("Notebook");
cbDesktop = new CheckBox("Desktop");
cbSmartphone.setAllowIndeterminate(true);
cbSmartphone.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent ae) {
if(cbSmartphone.isIndeterminate())
response.setText("Smartphone state is indeterminate.");
else if(cbSmartphone.isSelected())
response.setText("Smartphone was just selected.");
else
response.setText("Smartphone was just cleared.");
showAll();
}
});
cbTablet.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent ae) {
if(cbTablet.isSelected())
response.setText("Tablet was just selected.");
else
response.setText("Tablet was just cleared.");
showAll();
}
});
cbNotebook.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent ae) {
if(cbNotebook.isSelected())
response.setText("Notebook was just selected.");
else
response.setText("Notebook was just cleared.");
showAll();
}
});
cbDesktop.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent ae) {
if(cbDesktop.isSelected())
response.setText("Desktop was just selected.");
else
response.setText("Desktop was just cleared.");
showAll();
}
});
rootNode.getChildren().addAll(heading, cbSmartphone, cbTablet, cbNotebook, cbDesktop, response, selected);
myStage.show();
showAll();
}
void showAll() {
computers = "";
if(cbSmartphone.isSelected()) computers = "Smartphone";
if(cbTablet.isSelected()) computers += "Tablet";
if(cbNotebook.isSelected()) computers += "Notebook";
if(cbDesktop.isSelected()) computers += "Desktop";
selected.setText("Computers selected: " + computers);
}
}