-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical39.java
More file actions
64 lines (54 loc) · 2.06 KB
/
practical39.java
File metadata and controls
64 lines (54 loc) · 2.06 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
//Write a program to create a checkbox to choose one option among the given choices.
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class practical39 extends Application {
@Override
public void start(Stage primaryStage) {
Label instructionLabel = new Label("Select your favorite programming language:");
Label resultLabel = new Label("You selected: None");
// Creating the checkboxes
CheckBox chkJava = new CheckBox("Java");
CheckBox chkPython = new CheckBox("Python");
CheckBox chkCpp = new CheckBox("C++");
// Event handler for Java checkbox
chkJava.setOnAction(e -> {
if (chkJava.isSelected()) {
chkPython.setSelected(false);
chkCpp.setSelected(false);
resultLabel.setText("You selected: Java");
}
});
// Event handler for Python checkbox
chkPython.setOnAction(e -> {
if (chkPython.isSelected()) {
chkJava.setSelected(false);
chkCpp.setSelected(false);
resultLabel.setText("You selected: Python");
}
});
// Event handler for C++ checkbox
chkCpp.setOnAction(e -> {
if (chkCpp.isSelected()) {
chkJava.setSelected(false);
chkPython.setSelected(false);
resultLabel.setText("You selected: C++");
}
});
// Layout setup
VBox root = new VBox(15); // 15px spacing between elements
root.setAlignment(Pos.CENTER);
root.getChildren().addAll(instructionLabel, chkJava, chkPython, chkCpp, resultLabel);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Checkbox Selection");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}