GeezerVison is showing github.com — JFX · Kowus/Source-Code-from-Tutorials@19b7643
File tree
Expand file treeCollapse file tree
Open diff view settings
030_bindingPropertiesExample
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +44Lines changed: 44 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import javafx.application.Application; |
| 2 | +import javafx.beans.property.IntegerProperty; |
| 3 | +import javafx.beans.property.SimpleIntegerProperty; |
| 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 | + Stage window; |
| 12 | + Button button; |
| 13 | + |
| 14 | + public static void main(String[] args) { |
| 15 | + launch(args); |
| 16 | + } |
| 17 | + |
| 18 | + @Override |
| 19 | + public void start(Stage primaryStage) throws Exception { |
| 20 | + window = primaryStage; |
| 21 | + window.setTitle("thenewboston"); |
| 22 | + |
| 23 | + IntegerProperty x = new SimpleIntegerProperty(3); |
| 24 | + IntegerProperty y = new SimpleIntegerProperty(); |
| 25 | + |
| 26 | + y.bind(x.multiply(10)); |
| 27 | + System.out.println("x: " + x.getValue()); |
| 28 | + System.out.println("y: " + y.getValue() + "\n"); |
| 29 | + |
| 30 | + x.setValue(9); |
| 31 | + System.out.println("x: " + x.getValue()); |
| 32 | + System.out.println("y: " + y.getValue() + "\n"); |
| 33 | + |
| 34 | + button = new Button("Submit"); |
| 35 | + |
| 36 | + StackPane layout = new StackPane(); |
| 37 | + layout.getChildren().add(button); |
| 38 | + Scene scene = new Scene(layout, 300, 250); |
| 39 | + window.setScene(scene); |
| 40 | + window.show(); |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | +} |
Collapse file
Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import javafx.application.Application; |
| 2 | +import javafx.geometry.Pos; |
| 3 | +import javafx.scene.Scene; |
| 4 | +import javafx.scene.control.Label; |
| 5 | +import javafx.scene.control.TextField; |
| 6 | +import javafx.scene.layout.HBox; |
| 7 | +import javafx.scene.layout.VBox; |
| 8 | +import javafx.stage.Stage; |
| 9 | + |
| 10 | +public class Main extends Application { |
| 11 | + |
| 12 | + Stage window; |
| 13 | + |
| 14 | + public static void main(String[] args) { |
| 15 | + launch(args); |
| 16 | + } |
| 17 | + |
| 18 | + @Override |
| 19 | + public void start(Stage primaryStage) throws Exception { |
| 20 | + window = primaryStage; |
| 21 | + window.setTitle("thenewboston"); |
| 22 | + |
| 23 | + //Input and labels |
| 24 | + TextField userInput = new TextField(); |
| 25 | + userInput.setMaxWidth(200); |
| 26 | + Label firstLabel = new Label("Welcome to the site "); |
| 27 | + Label secondLabel = new Label(); |
| 28 | + |
| 29 | + HBox bottomText = new HBox(firstLabel, secondLabel); |
| 30 | + bottomText.setAlignment(Pos.CENTER); |
| 31 | + VBox vBox = new VBox(10, userInput, bottomText); |
| 32 | + vBox.setAlignment(Pos.CENTER); |
| 33 | + |
| 34 | + secondLabel.textProperty().bind(userInput.textProperty()); |
| 35 | + |
| 36 | + Scene scene = new Scene(vBox, 300, 200); |
| 37 | + window.setScene(scene); |
| 38 | + window.show(); |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | +} |