-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminPanel.java
More file actions
86 lines (68 loc) · 3.04 KB
/
AdminPanel.java
File metadata and controls
86 lines (68 loc) · 3.04 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
74
75
76
77
78
79
80
81
82
83
84
85
86
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AdminPanel extends JPanel {
private int width = 100;
private int height = 30;
private JTextField usrInput;
private JPasswordField pwInput;
private String username;
private String password;
private MovieTheatreApp app;
public AdminPanel(MovieTheatreApp app,UserDatabaseManager userDBM) {
this.app = app;
JLabel usrLabel = new JLabel("Username:");
JLabel pwLabel = new JLabel("Password:");
usrInput = new JTextField(15);
pwInput = new JPasswordField(15);
usrInput.setPreferredSize(new Dimension(width, height));
pwInput.setPreferredSize(new Dimension(width, height));
JButton submitButton = new JButton("Submit");
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
username = usrInput.getText();
System.out.println(username);
password = new String(pwInput.getPassword());
//System.out.println("PW IN ACTION PERFORMED");
//System.out.println(password);
// Need to change/add to this stuff still
if (password.equals("password") && username.equals("admin")) {
JOptionPane.showMessageDialog(app, "Logged in successfully!");
usrInput.setText("");
pwInput.setText("");
app.setCurrentUser(2); // indicate whoevers using our app rn is an Admin !!!
app.switchToMovieList(); // not sure what to switch to, whatever admins should be able to do
}
else {
JOptionPane.showMessageDialog(app, "Incorrect username or password.");
}
}
});
setLayout(new BorderLayout());
JPanel headerPanel = new JPanel();
JLabel title = new JLabel("Sign In");
headerPanel.add(title);
this.add(headerPanel, BorderLayout.NORTH);
JPanel submitPanel = new JPanel();
submitPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
submitPanel.add(submitButton);
this.add(submitPanel, BorderLayout.PAGE_END);
JPanel clientPanel = new JPanel();
clientPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 5, 5, 5);
int row = 0;
addComponent(clientPanel, usrLabel, 0, row, gbc);
addComponent(clientPanel, usrInput, 1, row++, gbc);
addComponent(clientPanel, pwLabel, 0, row, gbc);
addComponent(clientPanel, pwInput, 1, row++, gbc);
this.add(clientPanel, BorderLayout.CENTER);
}
private void addComponent(JPanel panel, Component component, int gridx, int gridy, GridBagConstraints gbc) {
gbc.gridx = gridx;
gbc.gridy = gridy;
panel.add(component, gbc);
}
}