Skip to content

Commit 47b100f

Browse files
authored
Add files via upload
1 parent 502c5a0 commit 47b100f

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

App.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package basicGUI;
2+
3+
import javafx.application.Application;
4+
import javafx.scene.Scene;
5+
import javafx.stage.Stage;
6+
7+
// App needs to extend Application to set up the GUI
8+
public class App extends Application {
9+
10+
// Must launch args
11+
public static void main(String[] args) {
12+
launch(args);
13+
}
14+
15+
// Override the start method in Application
16+
@Override
17+
public void start(Stage stage) {
18+
// Creates a pane organizer to call getRoot and get the BorderPane I setup at the root
19+
PaneOrganizer organizer = new PaneOrganizer();
20+
// Creates the scene. Root, Width, Height
21+
Scene scene = new Scene(organizer.getRoot(), 500, 500);
22+
// Sets the scene
23+
stage.setScene(scene);
24+
// Shows the scene
25+
stage.show();
26+
}
27+
}

PaneOrganizer.java

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)