-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_38.java
More file actions
38 lines (30 loc) · 1.09 KB
/
Practical_38.java
File metadata and controls
38 lines (30 loc) · 1.09 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
/* Question := Write a program that creates a button and generate a click event to
display ”Welcome to JavaFx ”.*/
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Practical_38 extends Application {
@Override
public void start(Stage primaryStage) {
// Create a button and a label
Button button = new Button("Click me!");
Label label = new Label("Welcome to JavaFx");
button.setOnAction(event -> {
boolean isVisible = label.isVisible();
label.setVisible(!isVisible);
});
VBox vbox = new VBox();
vbox.setAlignment(Pos.CENTER);
vbox.getChildren().addAll(label,button);
Scene scene = new Scene(vbox, 300, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}