-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical38.java
More file actions
37 lines (30 loc) · 1.13 KB
/
practical38.java
File metadata and controls
37 lines (30 loc) · 1.13 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
// 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 practical38 extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button("Click Me!");
Label label = new Label(); // Empty label initially
// Generate a click event using a lambda expression
btn.setOnAction(e -> {
label.setText("Welcome to JavaFx");
System.out.println("Welcome to JavaFx"); // Also displays in the terminal
});
VBox root = new VBox(15);
root.setAlignment(Pos.CENTER);
root.getChildren().addAll(btn, label);
Scene scene = new Scene(root, 300, 200);
primaryStage.setTitle("JavaFX Button Event");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}