GeezerVison is showing github.com — Added JavaFX source code. · SF5/Source-Code-from-Tutorials@9f8cc7e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import javafx.application.Application; |
| 2 | +import javafx.scene.Scene; |
| 3 | +import javafx.scene.control.Button; |
| 4 | +import javafx.scene.layout.StackPane; |
| 5 | +import javafx.stage.Stage; |
| 6 | + |
| 7 | +public class Main extends Application { |
| 8 | + |
| 9 | + Button button; |
| 10 | + |
| 11 | + public static void main(String[] args) { |
| 12 | + launch(args); |
| 13 | + } |
| 14 | + |
| 15 | + @Override |
| 16 | + public void start(Stage primaryStage) throws Exception { |
| 17 | + primaryStage.setTitle("Title of the Window"); |
| 18 | + button = new Button(); |
| 19 | + button.setText("Click me"); |
| 20 | + StackPane layout = new StackPane(); |
| 21 | + layout.getChildren().add(button); |
| 22 | + Scene scene = new Scene(layout, 300, 250); |
| 23 | + primaryStage.setScene(scene); |
| 24 | + primaryStage.show(); |
| 25 | + } |
| 26 | + |
| 27 | +} |
Collapse file
Copy file name to clipboard +41Lines changed: 41 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import javafx.application.Application; |
| 2 | +import javafx.event.ActionEvent; |
| 3 | +import javafx.event.EventHandler; |
| 4 | +import javafx.scene.Scene; |
| 5 | +import javafx.scene.control.Button; |
| 6 | +import javafx.scene.layout.StackPane; |
| 7 | +import javafx.stage.Stage; |
| 8 | + |
| 9 | +public class Main extends Application implements EventHandler<ActionEvent> { |
| 10 | + |
| 11 | + Button button; |
| 12 | + |
| 13 | + public static void main(String[] args) { |
| 14 | + launch(args); |
| 15 | + } |
| 16 | + |
| 17 | + @Override |
| 18 | + public void start(Stage primaryStage) { |
| 19 | + primaryStage.setTitle("Title of Window"); |
| 20 | + button = new Button(); |
| 21 | + button.setText("Hey baby"); |
| 22 | + |
| 23 | + //This class will handle the button events |
| 24 | + button.setOnAction(this); |
| 25 | + |
| 26 | + StackPane layout = new StackPane(); |
| 27 | + layout.getChildren().add(button); |
| 28 | + Scene scene = new Scene(layout, 300, 250); |
| 29 | + primaryStage.setScene(scene); |
| 30 | + primaryStage.show(); |
| 31 | + } |
| 32 | + |
| 33 | + //When button is clicked, handle() gets called |
| 34 | + //Button click is an ActionEvent (also MouseEvents, TouchEvents, etc...) |
| 35 | + @Override |
| 36 | + public void handle(ActionEvent event) { |
| 37 | + if (event.getSource() == button) |
| 38 | + System.out.println("Hey Charlie!"); |
| 39 | + } |
| 40 | + |
| 41 | +} |
Collapse file
Copy file name to clipboard +41Lines changed: 41 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import javafx.application.Application; |
| 2 | +import javafx.event.ActionEvent; |
| 3 | +import javafx.event.EventHandler; |
| 4 | +import javafx.scene.Scene; |
| 5 | +import javafx.scene.control.Button; |
| 6 | +import javafx.scene.layout.StackPane; |
| 7 | +import javafx.stage.Stage; |
| 8 | + |
| 9 | +public class Main extends Application { |
| 10 | + |
| 11 | + Button button; |
| 12 | + |
| 13 | + public static void main(String[] args) { |
| 14 | + launch(args); |
| 15 | + } |
| 16 | + |
| 17 | + @Override |
| 18 | + public void start(Stage primaryStage) { |
| 19 | + primaryStage.setTitle("Title of Window"); |
| 20 | + button = new Button(); |
| 21 | + button.setText("Click Me"); |
| 22 | + |
| 23 | + button.setOnAction(e -> System.out.println("Lambda expressions are awesome!")); |
| 24 | + |
| 25 | + /* |
| 26 | + button.setOnAction(new EventHandler<ActionEvent>() { |
| 27 | + @Override |
| 28 | + public void handle(ActionEvent event) { |
| 29 | + System.out.println("Handle event using anonymous inner classes"); |
| 30 | + } |
| 31 | + }); |
| 32 | + */ |
| 33 | + |
| 34 | + StackPane layout = new StackPane(); |
| 35 | + layout.getChildren().add(button); |
| 36 | + Scene scene = new Scene(layout, 300, 250); |
| 37 | + primaryStage.setScene(scene); |
| 38 | + primaryStage.show(); |
| 39 | + } |
| 40 | + |
| 41 | +} |