|
| 1 | +package basicGUI; |
| 2 | + |
| 3 | +import javafx.geometry.Pos; |
| 4 | +import javafx.scene.control.Button; |
| 5 | +import javafx.scene.control.Label; |
| 6 | +import javafx.scene.layout.BorderPane; |
| 7 | +import javafx.scene.layout.HBox; |
| 8 | +import javafx.scene.layout.VBox; |
| 9 | + |
| 10 | +// PaneOrganizer sets up the GUI |
| 11 | +public class PaneOrganizer { |
| 12 | + // Creates the BorderPane which will be the root |
| 13 | + private BorderPane _root; |
| 14 | + |
| 15 | + public PaneOrganizer() { |
| 16 | + this.setupRoot(); |
| 17 | + } |
| 18 | + |
| 19 | + // setupRoot instantiates the BorderPane _root and calls setup methods for its contents |
| 20 | + private void setupRoot() { |
| 21 | + _root = new BorderPane(); |
| 22 | + // Sets each object in a section of the BorderPane |
| 23 | + _root.setTop(this.setupHBox()); |
| 24 | + _root.setLeft(this.setupVBox()); |
| 25 | + _root.setCenter(this.setupLabel()); |
| 26 | + } |
| 27 | + |
| 28 | + // getRoot returns the BorderPane _root so it can be used to setup the scene |
| 29 | + public BorderPane getRoot() { |
| 30 | + return _root; |
| 31 | + } |
| 32 | + |
| 33 | + // setupHBox creates an HBox |
| 34 | + private HBox setupHBox() { |
| 35 | + // Sets up HBox and its separation |
| 36 | + HBox hbox = new HBox(10); |
| 37 | + hbox.setPrefHeight(50); |
| 38 | + // Sets the alignment of HBox within its section of the BorderPane |
| 39 | + hbox.setAlignment(Pos.BOTTOM_CENTER); |
| 40 | + hbox.setStyle("-fx-background-color: blue;"); |
| 41 | + Button topButton1 = new Button("Top Button 1"); |
| 42 | + Button topButton2 = new Button("Top Button 2"); |
| 43 | + Button topButton3 = new Button("Top Button 3"); |
| 44 | + hbox.getChildren().addAll(topButton1, topButton2, topButton3); |
| 45 | + return hbox; |
| 46 | + } |
| 47 | + |
| 48 | + // setupVBox creates a VBox |
| 49 | + private VBox setupVBox() { |
| 50 | + // Sets up VBox and its separation |
| 51 | + VBox vbox = new VBox(20); |
| 52 | + vbox.setPrefWidth(95); |
| 53 | + // Sets the alignment of VBox within its section of the BorderPane |
| 54 | + vbox.setAlignment(Pos.CENTER_LEFT); |
| 55 | + vbox.setStyle("-fx-background-color: black;"); |
| 56 | + Button leftButton1 = new Button("Left Button 1"); |
| 57 | + Button leftButton2 = new Button("Left Button 2"); |
| 58 | + Button leftButton3 = new Button("Left Button 3"); |
| 59 | + vbox.getChildren().addAll(leftButton1, leftButton2, leftButton3); |
| 60 | + return vbox; |
| 61 | + } |
| 62 | + |
| 63 | + // setupLabel creates a Label |
| 64 | + private Label setupLabel() { |
| 65 | + Label label = new Label("Hello, I'm a red Label"); |
| 66 | + // Sets alignment of label within its section of the BorderPane |
| 67 | + label.setAlignment(Pos.CENTER); |
| 68 | + // Sets background color behind the label |
| 69 | + label.setStyle("-fx-background-color: red;"); |
| 70 | + return label; |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments