-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorization.java
More file actions
73 lines (66 loc) · 2.38 KB
/
Authorization.java
File metadata and controls
73 lines (66 loc) · 2.38 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
70
71
72
73
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class Authorization {
JFrame window;
JTextField login, password;
public Authorization() {
window = new JFrame("Authorization");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(250, 150);
window.setLayout(new GridLayout(0,2));
initFields();
initButtons();
window.setVisible(true);
}
public void initButtons() {
JButton in = new JButton("Sign In");
in.addActionListener(new ButtonListener());
window.add(in);
JButton up = new JButton("Sign Up");
up.addActionListener(new ButtonListener());
window.add(up);
}
public void initFields() {
window.add(new JLabel("Login"));
login = new JTextField();
window.add(login);
window.add(new JLabel("Password"));
password = new JTextField();
window.add(password);
}
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (login.getText().isEmpty() || password.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "Fields must be filled!");
return;
}
int result;
switch(e.getActionCommand()) {
case "Sign In":
UIClient.send(("login:" + login.getText() + ",password:" + password.getText() + ",method:findUser").getBytes());
//id = UI.bd.findUser(login.getText(), password.getText());
result = Integer.parseInt(new String(UIClient.get()).trim());
System.out.print(result);
if(result > 0) {
window.setVisible(false);
new MainWindow(login.getText(), password.getText());
} else {
JOptionPane.showMessageDialog(null, "Invalid data entered!");
}
break;
case "Sign Up":
UIClient.send(("login:" + login.getText() + ",password:" + password.getText() + ",method:createUser").getBytes());
result = Integer.parseInt(new String(UIClient.get()).trim());
if (result > 0) {
JOptionPane.showMessageDialog(null, "User registered successfully! Sign in. Login will be done automatically");
new MainWindow(login.getText(), password.getText());
} else {
JOptionPane.showMessageDialog(null, "This login already exists or not valid Data!");
}
break;
}
}
}
}