-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain9.java
More file actions
71 lines (52 loc) · 2.56 KB
/
Copy pathMain9.java
File metadata and controls
71 lines (52 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package JavaFXDemo;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Main9 extends Application {
//Application is the class that inherits all the functionality
Stage window;
public static void main(String[] args) {
launch(args);
//launch(args) is a method that is called once the main program starts and goes inside the application class
//it sets ups your javafx application
}
@Override
public void start(Stage primaryStage) throws Exception {
//the application will call a method called start, start is actually overridden because you are inheriting
//it from the application class. The start method passes in the primaryStage which is the main window for
//the application.
window = primaryStage;
window.setTitle("thenewboston - JavaFX"); //sets the title of the window
GridPane grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));//amount of padding you want to add to each edge, i.e 10 pixel
//padding around your layout and the window
grid.setVgap(8); //setVgap method sets the padding for vertical spacing for cells in the grid
grid.setHgap(10);//setHgap method sets the padding for horizontal spacing for cells in the grid
//Name label
Label nameLabel = new Label("Username:");
GridPane.setConstraints(nameLabel, 0, 0);//setConstraints positions the object in the grid. This method
//accepts 3 parameters, object, column index, row index. 0 indicates first, 1 indicates seconds, etc
//Name input
TextField nameInput = new TextField("Bucky");
GridPane.setConstraints(nameInput, 1, 0);
//Pasword label
Label passLabel = new Label("Password:");
GridPane.setConstraints(passLabel, 0, 1);
//Password input
TextField passInput = new TextField();
passInput.setPromptText("password"); //password hint
GridPane.setConstraints(passInput, 1, 1);
Button loginButton = new Button("Log in");
GridPane.setConstraints(loginButton, 1, 2);
grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, loginButton);//adds all the objects to
//the grid
Scene scene = new Scene(grid, 300, 200);
window.setScene(scene);
window.show(); //show the window
}
}