diff --git a/Main.java b/Main.java index 2af67a95fa7b843cbf8f68288189989997d353e0..76f50755985a59a38f5b3e95659af4aed20e7f53 100644 --- a/Main.java +++ b/Main.java @@ -9,6 +9,7 @@ import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; @@ -24,26 +25,26 @@ public class Main extends Application { root.setMinWidth(600); root.setMinHeight(600); root.setSpacing(20); - root.setBackground(new Background(new BackgroundFill(Color.GREEN, null, null))); //Look for a green box + root.setBackground(new Background(new BackgroundFill(Color.GREEN, null, null))); // Look for a green box - //These are nodes that can be put in a layout, read docs. + // These are nodes that can be put in a layout, read docs. TextField field = new TextField(); Button button = new Button("Click me!"); - //Canvas is special, because you can draw on it. + // Canvas is special, because you can draw on it. Canvas canvas = new Canvas(); canvas.setHeight(200); canvas.setWidth(200); - //Using the graphics context, you can draw. Canvas has x and y coordinates. + // Using the graphics context, you can draw. Canvas has x and y coordinates. GraphicsContext gc = canvas.getGraphicsContext2D(); gc.setFill(Color.BLACK); gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); - //Vertical box, nodes will stack on y axis. + // Vertical box, nodes will stack on y axis. VBox box = new VBox(); box.setMinHeight(300); box.setMinWidth(300); box.setMaxHeight(400); - box.setBackground(new Background(new BackgroundFill(Color.PINK, null, null))); //Look for a pink box! + box.setBackground(new Background(new BackgroundFill(Color.PINK, null, null))); // Look for a pink box! // This is a listener, when you press the button this code will execute button.setOnAction(new EventHandler<ActionEvent>() { @@ -54,26 +55,49 @@ public class Main extends Application { box.getChildren().add(label); field.setText(""); - //Special case, try it - if(text.equals("TDDC77")){ + // Special case, try it + if (text.equals("TDDC77")) { gc.setFill(Color.LIGHTBLUE); gc.fillOval(50, 50, 100, 100); } } }); - - Scene scene = new Scene(root); // Create the scene with root element primaryStage.setScene(scene); - root.getChildren().add(field); //put field in green box - root.getChildren().add(button); //put button in green box - root.getChildren().add(box); //put pink box in green box - root.getChildren().add(canvas); //put canvas in green box - box.getChildren().add(new Label("Hello world")); //put label in pink box + root.getChildren().add(field); // put field in green box + root.getChildren().add(button); // put button in green box + root.getChildren().add(box); // put pink box in green box + root.getChildren().add(canvas); // put canvas in green box + box.getChildren().add(new Label("Hello world")); // put label in pink box + + // Grid + GridPane gridPane = new GridPane(); + Button button1 = new Button("Button 1"); + Button button2 = new Button("Button 2"); + Button button3 = new Button("Button 3"); + Button button4 = new Button("Button 4"); + Button button5 = new Button("Button 5"); + Button button6 = new Button("Button 6"); + + // gridPane.setBackground(new Background(new BackgroundFill(Color.PINK, null, null))); // Look for a pink box! + + gridPane.add(button1, 0, 0, 2, 2); + + gridPane.add(button2, 2, 0, 1, 1); + gridPane.add(button3, 2, 1, 1, 1); + gridPane.add(button4, 0, 2, 1, 1); + gridPane.add(button5, 1, 2, 1, 1); + gridPane.add(button6, 2, 2, 1, 1); + gridPane.setGridLinesVisible(true); + + gridPane.setHgap(200); + gridPane.setVgap(200); + + root.getChildren().add(gridPane); - //Last thing to do is show + // Last thing to do is show primaryStage.show(); }