1+ import javafx .application .Application ;
2+ import javafx .geometry .Insets ;
3+ import javafx .scene .Scene ;
4+ import javafx .scene .control .Button ;
5+ import javafx .scene .control .Label ;
6+ import javafx .scene .control .TextField ;
7+ import javafx .scene .layout .GridPane ;
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 - JavaFX" );
22+
23+ //GridPane with 10px padding around edge
24+ GridPane grid = new GridPane ();
25+ grid .setPadding (new Insets (10 , 10 , 10 , 10 ));
26+ grid .setVgap (8 );
27+ grid .setHgap (10 );
28+
29+ //Name Label - constrains use (child, column, row)
30+ Label nameLabel = new Label ("Username:" );
31+ nameLabel .setId ("bold-label" );
32+ GridPane .setConstraints (nameLabel , 0 , 0 );
33+
34+ //Name Input
35+ TextField nameInput = new TextField ("Bucky" );
36+ GridPane .setConstraints (nameInput , 1 , 0 );
37+
38+ //Password Label
39+ Label passLabel = new Label ("Password:" );
40+ GridPane .setConstraints (passLabel , 0 , 1 );
41+
42+ //Password Input
43+ TextField passInput = new TextField ();
44+ passInput .setPromptText ("password" );
45+ GridPane .setConstraints (passInput , 1 , 1 );
46+
47+ //Login
48+ Button loginButton = new Button ("Log In" );
49+ GridPane .setConstraints (loginButton , 1 , 2 );
50+
51+ //Sign up
52+ Button signUpButton = new Button ("Sign Up" );
53+ signUpButton .getStyleClass ().add ("button-blue" );
54+ GridPane .setConstraints (signUpButton , 1 , 3 );
55+
56+ //Add everything to grid
57+ grid .getChildren ().addAll (nameLabel , nameInput , passLabel , passInput , loginButton , signUpButton );
58+
59+ Scene scene = new Scene (grid , 300 , 200 );
60+ scene .getStylesheets ().add ("Viper.css" );
61+ window .setScene (scene );
62+ window .show ();
63+ }
64+
65+
66+ }
0 commit comments