-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginScreen.java
88 lines (65 loc) · 2.91 KB
/
LoginScreen.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package bookstoreapp;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.geometry.*;
import javafx.scene.paint.Color;
import javafx.scene.*;
public class LoginScreen {
public Group display(){
Group screen = new Group();
TextField fieldUsername = new TextField();
TextField fieldPassword = new TextField();
Label greeting = new Label("Welcome to the Bookstore App!");
Label labelUser = new Label("Username:");
Label labelPass = new Label("Password: ");
Label errorLogin = new Label("");
Button buttonLogin = new Button("Login");
buttonLogin.setMaxSize(100, 200);
//button sizing and initalization
buttonLogin.setOnAction(e ->{
String username = fieldUsername.getText();
String password = fieldPassword.getText();
if(username.equals(owner.getUsername()) == true && password.equals(owner.getPassword()) == true){
//switch screen to owner main screen
}
else{
boolean login = false;
for(int i = 0; i < customers.size(); i++){
//customers is the arraylist of customers
if(username.equals(customers.get(i).getUser()) == true && password.equals(customers.get(i).getPass()) == true){
//switch screen to customer main screen
login = true;
}
}
if(login == false){
errorLogin.setText("Incorrect Login Credentials!");
errorLogin.setTextFill(Color.color(1,0,0));
fieldPassword.clear();
}
}
});
GridPane gridPane = new GridPane();
gridPane.add(greeting, 0, 0);
gridPane.add(labelUser, 0, 1);
gridPane.add(labelPass, 0, 2);
gridPane.add(fieldUsername, 1, 1);
gridPane.add(fieldPassword, 1, 2);
gridPane.add(buttonLogin, 1, 3);
gridPane.add(errorLogin, 1, 4);
//adding all the elements to a grid
gridPane.setHgap(5);
gridPane.setVgap(5);
gridPane.setAlignment(Pos.CENTER);
//formatting the grid
/*
Scene scene = new Scene(gridPane, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
^this is how i initialized the screen to test it using a main method
but idk how the main is gonna be so i mimicked the CustomerStartScreen,
feel free to change it, thanks again!
*/
screen.getChildren().addAll(gridPane);
return screen;
}
}