-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlertBoxError.java
161 lines (133 loc) · 5.21 KB
/
AlertBoxError.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
/**
* AlertBox
*/
public class AlertBoxError {
public static void display(String title, String message) {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
Label alertlogin = new Label(message);
Button closebtn = new Button("Close the window");
closebtn.setOnAction(e -> window.close());
VBox layout = new VBox(10);
layout.getStylesheets().add("Gui.css");
layout.getChildren().addAll(alertlogin, closebtn);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout, 400, 300);
window.setScene(scene);
window.showAndWait();
}
public static String getUsernameforgot() {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Forgot Password?");
TextField getuser = new TextField();
Label alertlogin = new Label("Forgot Your Password? Type you Username.");
Button closebtn = new Button("Enter");
closebtn.setOnAction(e -> {
if (getuser.getText().equals("") || getuser.getText().equals(null)) {
AlertBoxError.display("Error", "Please Fillin Username");
} else
try {
if (check(getuser.getText()) == false) {
AlertBoxError.display("Error", "Wrong Username");
} else
window.close();
} catch (ClassNotFoundException | IOException e1) {
e1.printStackTrace();
}
});
Button exit = new Button("Back");
exit.setOnAction(e -> window.close());
window.setOnCloseRequest(e -> window.close());
VBox layout = new VBox(10);
layout.getStylesheets().add("Gui.css");
layout.getChildren().addAll(getuser,alertlogin,closebtn,exit);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout,400,300);
window.setScene(scene);
window.showAndWait();
return getuser.getText();
}
public static boolean check(String username) throws IOException, ClassNotFoundException {
File file = new File("userdata.dat");
User a = null;
boolean userexist = false;
if (file.exists()) {
FileInputStream fin = new FileInputStream("userdata.dat");
ObjectInputStream in = new ObjectInputStream(fin);
while (fin.available() != 0) {
a = (User) in.readObject();
if (username.equals(a.getUsername())) {
userexist = true;
break;
}
}
in.close();
}
if(userexist == false){return userexist;}
else {return userexist;}
}
static Boolean exor;
public static Boolean confirm(String title, String message) {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
Label alert = new Label(message);
Button yesbtn = new Button("Yes");
yesbtn.setOnAction(e -> {
exor = true;
window.close();
});
Button nobtn = new Button("No");
nobtn.setOnAction(e -> {
exor = false;
window.close();
});
VBox layout = new VBox(10);
layout.getChildren().addAll(alert,yesbtn,nobtn);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout,200,200);
layout.getStylesheets().add("Gui.css");
window.setScene(scene);
window.showAndWait();
return exor;
}
public static String post() {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Set Picture");
TextField getuser = new TextField();
Label alertlogin = new Label("Image URL");
Button enter = new Button("Enter");
enter.setOnAction(e -> {
if (getuser.getText().equals("") || getuser.getText().equals(null)) {
AlertBoxError.display("Error", "Please Fillin Box");
}
else window.close();
});
Button exit = new Button("Back");
exit.setOnAction(e -> window.close());
window.setOnCloseRequest(e -> window.close());
VBox layout = new VBox(10);
layout.getChildren().addAll(getuser,alertlogin,enter,exit);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout,400,300);
layout.getStylesheets().add("Gui.css");
window.setScene(scene);
window.showAndWait();
return getuser.getText();
}
}