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+ GridPane .setConstraints (nameLabel , 0 , 0 );
32+
33+ //Name Input
34+ TextField nameInput = new TextField ("Bucky" );
35+ GridPane .setConstraints (nameInput , 1 , 0 );
36+
37+ //Password Label
38+ Label passLabel = new Label ("Password:" );
39+ GridPane .setConstraints (passLabel , 0 , 1 );
40+
41+ //Password Input
42+ TextField passInput = new TextField ();
43+ passInput .setPromptText ("password" );
44+ GridPane .setConstraints (passInput , 1 , 1 );
45+
46+ //Login
47+ Button loginButton = new Button ("Log In" );
48+ GridPane .setConstraints (loginButton , 1 , 2 );
49+
50+ //Add everything to grid
51+ grid .getChildren ().addAll (nameLabel , nameInput , passLabel , passInput , loginButton );
52+
53+ Scene scene = new Scene (grid , 300 , 200 );
54+ window .setScene (scene );
55+ window .show ();
56+ }
57+
58+
59+ }
0 commit comments