diff --git a/chentony/JavaFxTutorial1-3/EventHandlerTutorial1-3.java b/chentony/JavaFxTutorial1-3/EventHandlerTutorial1-3.java new file mode 100644 index 0000000..38e9bac --- /dev/null +++ b/chentony/JavaFxTutorial1-3/EventHandlerTutorial1-3.java @@ -0,0 +1,41 @@ +package sample; + +import javafx.application.Application; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.control.Button; +import javafx.scene.layout.StackPane; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Main extends Application{ + + Button button; + + @Override + public void start(Stage primaryStage) throws Exception{ + primaryStage.setTitle("Title of the Window"); + + button = new Button(); + button.setText("Click me"); + button.setOnAction(e -> { + System.out.println("hey now brown cow"); + System.out.println("PokemonGo"); + }); + + StackPane layout = new StackPane(); + layout.getChildren().add(button); + + Scene scene = new Scene(layout, 300, 250); + primaryStage.setScene(scene); + primaryStage.show(); + } + + + + public static void main(String[] args) { + launch(args); + } +} diff --git a/chentony/JavaFxTutorial10/Main.java b/chentony/JavaFxTutorial10/Main.java new file mode 100644 index 0000000..ee84da1 --- /dev/null +++ b/chentony/JavaFxTutorial10/Main.java @@ -0,0 +1,68 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + Button button; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Tony Chen"); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(10, 10, 10, 10)); + gridPane.setVgap(8); + gridPane.setHgap(10); + + //Form + TextField nameInput = new TextField(); + button = new Button("Click me"); + button.setOnAction(e -> isInt(nameInput, nameInput.getText()) ); + + + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().addAll(nameInput, button); + + Scene scene = new Scene(layout, 300, 250); + window.setScene(scene); + window.show(); + + + } + + + public static void main(String[] args) { + + launch(args); + } + + private boolean isInt(TextField input, String message){ + try{ + int age = Integer.parseInt(input.getText()); + System.out.println("User is " + age); + return true; + }catch(NumberFormatException e){ + System.out.println("Error: " + message + " is not a number"); + return false; + + } + } + +} diff --git a/chentony/JavaFxTutorial11/Main.java b/chentony/JavaFxTutorial11/Main.java new file mode 100644 index 0000000..1acaf2d --- /dev/null +++ b/chentony/JavaFxTutorial11/Main.java @@ -0,0 +1,72 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + Button button; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + + + //Checkboxes + CheckBox box1 = new CheckBox("Bacon"); + CheckBox box2 = new CheckBox("Tuna"); + box2.setSelected(true); + + + //Button + button = new Button("Order Now"); + button.setOnAction(e -> handleOptions(box1, box2)); + + + + + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().addAll(box1, box2, button); + + Scene scene = new Scene(layout, 300, 250); + window.setScene(scene); + window.show(); + + + } + + + + public static void main(String[] args) { + + launch(args); + } + + private void handleOptions(CheckBox box1, CheckBox box2){ + String message = "Users order:\n"; + + if(box1.isSelected()) + message += "Bacon\n"; + if(box2.isSelected()) + message += "Tuna\n"; + + System.out.println(message); + } + +} diff --git a/chentony/JavaFxTutorial12/Main.java b/chentony/JavaFxTutorial12/Main.java new file mode 100644 index 0000000..baf0ebd --- /dev/null +++ b/chentony/JavaFxTutorial12/Main.java @@ -0,0 +1,63 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + Button button; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + + + + //Button + button = new Button("Order Now"); + + ChoiceBox choiceBox = new ChoiceBox<>(); + //getItems returns the ObserableList object which oyu can add items to + choiceBox.getItems().add("Apples"); + choiceBox.getItems().add("Bananas"); + choiceBox.getItems().addAll("Bacon", "Ham", "Meatballs"); + + choiceBox.setValue("Apples"); + + button.setOnAction(e -> getChoice(choiceBox)); + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().addAll(choiceBox, button); + + Scene scene = new Scene(layout, 300, 250); + window.setScene(scene); + window.show(); + + + } + + + + public static void main(String[] args) { + + launch(args); + } + + private void getChoice(ChoiceBox choiceBox){ + String food = choiceBox.getValue(); + System.out.println(food); + } + +} diff --git a/chentony/JavaFxTutorial13/Main.java b/chentony/JavaFxTutorial13/Main.java new file mode 100644 index 0000000..06e7b82 --- /dev/null +++ b/chentony/JavaFxTutorial13/Main.java @@ -0,0 +1,62 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + Button button; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + + + + //Button + button = new Button("Order Now"); + + ChoiceBox choiceBox = new ChoiceBox<>(); + //getItems returns the ObserableList object which you can add items to + choiceBox.getItems().add("Apples"); + choiceBox.getItems().add("Bananas"); + choiceBox.getItems().addAll("Bacon", "Ham", "Meatballs"); + choiceBox.setValue("Apples"); + + //Listen for selection changes + choiceBox.getSelectionModel().selectedItemProperty().addListener( (v, oldValue, newValue) -> System.out.println(newValue)); + + + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().addAll(choiceBox, button); + + Scene scene = new Scene(layout, 300, 250); + window.setScene(scene); + window.show(); + + + } + + + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial14 - ComboBox/Main.java b/chentony/JavaFxTutorial14 - ComboBox/Main.java new file mode 100644 index 0000000..3aecf88 --- /dev/null +++ b/chentony/JavaFxTutorial14 - ComboBox/Main.java @@ -0,0 +1,66 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + Button button; + ComboBox comboBox; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + button = new Button("Submit"); + + comboBox = new ComboBox<>(); + comboBox.getItems().addAll( + "Good Will Hunting", + "St. Vincent", + "Blackhat" + ); + + comboBox.setPromptText("What is your favorite movie?"); + + comboBox.setEditable(true); + button.setOnAction(e -> printMovie()); + + comboBox.setOnAction(e -> System.out.println("User selected: " + comboBox.getValue())); + + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().addAll(comboBox, button); + + Scene scene = new Scene(layout, 300, 250); + window.setScene(scene); + window.show(); + + + } + + private void printMovie(){ + System.out.println(comboBox.getValue()); + } + + + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial15 - ListView/Main.java b/chentony/JavaFxTutorial15 - ListView/Main.java new file mode 100644 index 0000000..3a1afeb --- /dev/null +++ b/chentony/JavaFxTutorial15 - ListView/Main.java @@ -0,0 +1,79 @@ +package sample; + +import javafx.application.Application; +import javafx.beans.Observable; +import javafx.collections.ObservableList; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + Button button; + ListView listView; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + button = new Button("Submit"); + + listView = new ListView<>(); + listView.getItems().addAll( + "Iron Man", + "Batman", + "Superman", + "Captain America", + "Spiderman", + "Thor" + ); + + listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + + button.setOnAction(e -> buttonClicked()); + + + + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().addAll(listView, button); + + Scene scene = new Scene(layout, 300, 250); + window.setScene(scene); + window.show(); + + + } + private void buttonClicked(){ + String message = ""; + ObservableList movies; + movies = listView.getSelectionModel().getSelectedItems(); + + for(String m: movies) + { + message += m + "\n"; + } + + System.out.print(message); + } + + + + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial16 - TreeView/Main.java b/chentony/JavaFxTutorial16 - TreeView/Main.java new file mode 100644 index 0000000..1416933 --- /dev/null +++ b/chentony/JavaFxTutorial16 - TreeView/Main.java @@ -0,0 +1,83 @@ +package sample; + +import javafx.application.Application; +import javafx.beans.Observable; +import javafx.collections.ObservableList; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + TreeView treeView; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + + TreeItem root, Lakers, Knicks; + + //Root + root = new TreeItem<>(); + root.setExpanded(true); + + //Lakers + Lakers = makeBranch("Lakers", root); + makeBranch("Kobe", Lakers); + makeBranch("Shaq", Lakers); + makeBranch("Clarkson", Lakers); + + //Knicks + Knicks = makeBranch("Knicks", root); + makeBranch("Melo", Knicks); + makeBranch("Rose", Knicks); + makeBranch("Noah", Knicks); + + //Create tree + treeView = new TreeView<>(root); + treeView.setShowRoot(false); + treeView.getSelectionModel().selectedItemProperty() + .addListener((v, oldValue, newValue) -> { + if(newValue != null) + System.out.println(newValue.getValue()); + }); + + + + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().add(treeView); + + Scene scene = new Scene(layout, 300, 250); + window.setScene(scene); + window.show(); + + + } + + public TreeItem makeBranch(String title, TreeItem parent){ + TreeItem item = new TreeItem<>(title); + item.setExpanded(true); + parent.getChildren().add(item); + return item; + } + + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial17-20 - TableView/Main.java b/chentony/JavaFxTutorial17-20 - TableView/Main.java new file mode 100644 index 0000000..e6ee843 --- /dev/null +++ b/chentony/JavaFxTutorial17-20 - TableView/Main.java @@ -0,0 +1,125 @@ +package sample; + +import javafx.application.Application; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + TableView table; + TextField nameInput, priceInput, quantityInput; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + + //Name column + TableColumn nameColumn = new TableColumn<>("Name"); + nameColumn.setMinWidth(200); + nameColumn.setCellValueFactory(new PropertyValueFactory<>("name")); + + //Price column + TableColumn priceColumn = new TableColumn<>("Price"); + priceColumn.setMinWidth(100); + priceColumn.setCellValueFactory(new PropertyValueFactory<>("price")); + + //Quantity column + //Price column + TableColumn quantityColumn = new TableColumn<>("Quantity"); + quantityColumn.setMinWidth(100); + quantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity")); + + //Name input + nameInput = new TextField(); + nameInput.setPromptText("Name"); + nameInput.setMinWidth(100); + + //Price input + priceInput = new TextField(); + priceInput.setPromptText("Price"); + + //Quantity input + quantityInput = new TextField(); + quantityInput.setPromptText("Quantity"); + + //Button + Button addButton = new Button("Add"); + addButton.setOnAction(e -> addButtonClicked()); + + Button deleteButton = new Button("Delete"); + deleteButton.setOnAction(e -> deleteButtonClicked()); + + HBox hBox = new HBox(); + hBox.setPadding(new Insets(10, 10, 10, 10)); + hBox.setSpacing(10); + hBox.getChildren().addAll(nameInput, priceInput, quantityInput, addButton, deleteButton); + + + + table = new TableView<>(); + table.setItems(getProduct()); + table.getColumns().addAll(nameColumn, priceColumn, quantityColumn); + + //Layout + VBox layout = new VBox(); + layout.setPadding(new Insets(20, 20, 20, 20)); + layout.getChildren().addAll(table, hBox); + + Scene scene = new Scene(layout); + window.setScene(scene); + window.show(); + + + } + //Get all of the product + public ObservableList getProduct(){ + ObservableList products = FXCollections.observableArrayList(); + products.add(new Product("Laptop", 859.00, 20)); + products.add(new Product("Bouncy Ball", 2.59, 220)); + products.add(new Product("Toilet", 9.59, 74)); + products.add(new Product("Notebook", 5.00, 30)); + return products; + + } + + //Add Button clicked + public void addButtonClicked(){ + Product product = new Product(); + product.setName(nameInput.getText()); + product.setPrice(Double.parseDouble(priceInput.getText())); + product.setQuantity(Integer.parseInt(quantityInput.getText())); + table.getItems().add(product); + nameInput.clear(); + priceInput.clear(); + quantityInput.clear(); + } + + public void deleteButtonClicked(){ + ObservableList productsSelected, allProducts; + allProducts = table.getItems(); + productsSelected = table.getSelectionModel().getSelectedItems(); + + productsSelected.forEach(allProducts::remove); + } + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial17-20 - TableView/Product.java b/chentony/JavaFxTutorial17-20 - TableView/Product.java new file mode 100644 index 0000000..295406b --- /dev/null +++ b/chentony/JavaFxTutorial17-20 - TableView/Product.java @@ -0,0 +1,45 @@ +package sample; + + +public class Product { + + private String name; + private double price; + private int quantity; + + public Product(){ + this.name = ""; + this.price = 0; + this.quantity = 0; + } + + public Product(String name, double price, int quantity){ + this.name = name; + this.price = price; + this.quantity = quantity; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } +} diff --git a/chentony/JavaFxTutorial21-24 - Menus/Main.java b/chentony/JavaFxTutorial21-24 - Menus/Main.java new file mode 100644 index 0000000..845a9e6 --- /dev/null +++ b/chentony/JavaFxTutorial21-24 - Menus/Main.java @@ -0,0 +1,105 @@ +package sample; + +import javafx.application.Application; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + BorderPane layout; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Subways"); + + //file menu + Menu fileMenu = new Menu("File"); + + //Menu items + MenuItem newFile = new MenuItem("New..."); + newFile.setOnAction(e -> System.out.println("Create a new file")); + + fileMenu.getItems().add(newFile); + fileMenu.getItems().add(new MenuItem("Open...")); + fileMenu.getItems().add(new MenuItem("Save...")); + fileMenu.getItems().add(new SeparatorMenuItem()); + fileMenu.getItems().add(new MenuItem("Settings...")); + fileMenu.getItems().add(new SeparatorMenuItem()); + fileMenu.getItems().add(new MenuItem("Exit...")); + + + //Edite Menu + Menu editMenu = new Menu("_Edit"); + editMenu.getItems().add(new MenuItem("Cut")); + editMenu.getItems().add(new MenuItem("Copy")); + + MenuItem paste = new MenuItem("Paste"); + paste.setOnAction(e -> System.out.println("Pasting stuff")); + paste.setDisable(true); + editMenu.getItems().add(paste); + + //Help menu + Menu helpMenu = new Menu("Help"); + CheckMenuItem showLines = new CheckMenuItem("Show Line Numbers"); + showLines.setOnAction(e -> { + if(showLines.isSelected()) + System.out.println("Program will now display line numbers"); + else + System.out.println("Hiding line number"); + }); + CheckMenuItem autoSave = new CheckMenuItem("Enable Autosave"); + autoSave.setSelected(true); + helpMenu.getItems().addAll(showLines, autoSave); + + //Difficulty RadioMenuItems + Menu difficultyMenu = new Menu("Difficulty"); + ToggleGroup difficultyToggle =new ToggleGroup(); + + RadioMenuItem easy = new RadioMenuItem("Easy"); + RadioMenuItem medium = new RadioMenuItem("Medium"); + RadioMenuItem hard = new RadioMenuItem("Hard"); + + easy.setToggleGroup(difficultyToggle); + medium.setToggleGroup(difficultyToggle); + hard.setToggleGroup(difficultyToggle); + + difficultyMenu.getItems().addAll(easy, medium, hard); + + //Main menu bar + MenuBar menuBar = new MenuBar(); + menuBar.getMenus().addAll(fileMenu, editMenu, helpMenu, difficultyMenu); + + + //Layout + layout = new BorderPane(); + layout.setTop(menuBar); + + Scene scene = new Scene(layout, 400, 400); + window.setScene(scene); + window.show(); + + + } + + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial25-26 - CSS/Main.java b/chentony/JavaFxTutorial25-26 - CSS/Main.java new file mode 100644 index 0000000..a3e938c --- /dev/null +++ b/chentony/JavaFxTutorial25-26 - CSS/Main.java @@ -0,0 +1,78 @@ +package sample; + +import javafx.application.Application; +import javafx.beans.Observable; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + BorderPane layout; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Tony Chen"); + + GridPane gridPane = new GridPane(); + gridPane.setPadding(new Insets(10, 10, 10, 10)); + gridPane.setVgap(8); + gridPane.setHgap(10); + + //Name label + Label nameLabel = new Label("Username"); + nameLabel.setId("bold-label"); + GridPane.setConstraints(nameLabel, 0, 0); + + //Name input + TextField nameinput = new TextField(); + GridPane.setConstraints(nameinput, 1, 0); + + //Password + Label passLabel = new Label("Password"); + GridPane.setConstraints(passLabel, 0, 1); + + //Password input + TextField passinput = new TextField(); + passinput.setPromptText("Password"); + GridPane.setConstraints(passinput, 1, 1); + + //LoginButton + Button loginButton = new Button("Login"); + GridPane.setConstraints(loginButton,1,2); + + //Sign up + Button signupButton = new Button("Sign Up"); + signupButton.getStyleClass().add("button-blue"); + GridPane.setConstraints(signupButton,1,3); + + + + gridPane.getChildren().addAll(nameLabel,nameinput,passLabel,passinput,loginButton, signupButton); + + Scene scene = new Scene(gridPane, 300, 200); + scene.getStylesheets().add("/sample/Viper.css"); + window.setScene(scene); + window.show(); + } + + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial25-26 - CSS/Viper.css b/chentony/JavaFxTutorial25-26 - CSS/Viper.css new file mode 100644 index 0000000..971b243 --- /dev/null +++ b/chentony/JavaFxTutorial25-26 - CSS/Viper.css @@ -0,0 +1,20 @@ +.root{ + -fx-background-color: #383838; + -fx-font-size: 11pt; +} +.label{ + -fx-text-fill: #e8e8e8; +} +.button{ + -fx-background-color: linear-gradient(#dc9656, #ab4642); + -fx-text-fill: #FFFFFF; + -fx-background-radius: 6; +} +.button-blue{ + -fx-background-color:#7cafc2; + -fx-text-fill: #FFFFFF; + -fx-background-radius: 6; +} +#bold-label{ + -fx-font-weight: bold; +} \ No newline at end of file diff --git a/chentony/JavaFxTutorial27-30 - Binding/Main.java b/chentony/JavaFxTutorial27-30 - Binding/Main.java new file mode 100644 index 0000000..d8de79b --- /dev/null +++ b/chentony/JavaFxTutorial27-30 - Binding/Main.java @@ -0,0 +1,58 @@ +package sample; + +import javafx.application.Application; +import javafx.beans.Observable; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.layout.*; +import javafx.scene.text.Text; +import javafx.stage.Stage; + + +public class Main extends Application { + + Stage window; + Button button; + + @Override + public void start(Stage primaryStage) throws Exception{ + window = primaryStage; + window.setTitle("Tony Chen"); + + //Input and labels + TextField userinput = new TextField(); + userinput.setMaxWidth(200); + Label firstLabel = new Label("Welcome to the site "); + Label secondLabel = new Label(); + + HBox bottomtext = new HBox(firstLabel, secondLabel); + bottomtext.setAlignment(Pos.CENTER); + + VBox vBox = new VBox(10,userinput, bottomtext); + vBox.setAlignment(Pos.CENTER); + + secondLabel.textProperty().bind(userinput.textProperty()); + + Scene scene = new Scene(vBox, 300, 200); + window.setScene(scene); + window.show(); + } + + + public static void main(String[] args) { + + launch(args); + } + + + +} diff --git a/chentony/JavaFxTutorial27-30 - Binding/Person.java b/chentony/JavaFxTutorial27-30 - Binding/Person.java new file mode 100644 index 0000000..f39e30e --- /dev/null +++ b/chentony/JavaFxTutorial27-30 - Binding/Person.java @@ -0,0 +1,26 @@ +package sample; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class Person { + + private StringProperty firstName = new SimpleStringProperty(this, "firstName", ""); + + //Returns the StringProperty object + public StringProperty firstNameProperty() { + return firstName; + } + + //Returns the firstName value (ie. "Tony") + public String getFirstName() { + return firstName.get(); + } + + + //Set the firstName value + public void setFirstName(String firstName) { + this.firstName.set(firstName); + } +} + diff --git a/chentony/JavaFxTutorial31-35 - SceneBuilder/Controller.java b/chentony/JavaFxTutorial31-35 - SceneBuilder/Controller.java new file mode 100644 index 0000000..7a7786a --- /dev/null +++ b/chentony/JavaFxTutorial31-35 - SceneBuilder/Controller.java @@ -0,0 +1,11 @@ +package sample; + + + + +public class Controller { + public void loginButtonClicked(){ + System.out.println("User Logged in..."); + } + +} diff --git a/chentony/JavaFxTutorial31-35 - SceneBuilder/Main.java b/chentony/JavaFxTutorial31-35 - SceneBuilder/Main.java new file mode 100644 index 0000000..e57b730 --- /dev/null +++ b/chentony/JavaFxTutorial31-35 - SceneBuilder/Main.java @@ -0,0 +1,25 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Main extends Application { + + + public static void main(String[] args) { + launch(args); + } + + + @Override + public void start(Stage primaryStage) throws Exception { + Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); + primaryStage.setTitle("Hello World"); + primaryStage.setScene(new Scene(root, 800, 500)); + primaryStage.show(); + } + +} \ No newline at end of file diff --git a/chentony/JavaFxTutorial31-35 - SceneBuilder/sample.fxml b/chentony/JavaFxTutorial31-35 - SceneBuilder/sample.fxml new file mode 100644 index 0000000..8cee6bd --- /dev/null +++ b/chentony/JavaFxTutorial31-35 - SceneBuilder/sample.fxml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +