|
2 | 2 | * Provides the UI elements
|
3 | 3 | */
|
4 | 4 | import javax.swing.*;
|
5 |
| -import java.awt.GridLayout; |
| 5 | +import java.awt.*; |
6 | 6 | import java.awt.event.ActionEvent;
|
7 | 7 | import java.awt.event.ActionListener;
|
8 | 8 |
|
9 | 9 | public class UserModificationUI implements ChangeController{
|
10 | 10 | private JLabel label;
|
11 | 11 | public UserModificationUI() {
|
12 | 12 | final JFrame frame = new JFrame();
|
13 |
| - frame.setSize(1200, 100); |
| 13 | + frame.setSize(500, 300); |
| 14 | + |
14 | 15 | frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
15 |
| - frame.setLayout(new GridLayout()); |
| 16 | + frame.setLayout(new FlowLayout()); |
16 | 17 |
|
| 18 | +// Field for username |
17 | 19 | final JTextField usernameField = new JTextField("Enter your current username");
|
| 20 | + usernameField.setBounds(10, 25, 100, 25); |
18 | 21 | String username = (usernameField.getText());
|
19 | 22 |
|
| 23 | +// Field for password |
20 | 24 | final JTextField passwordField = new JTextField("Enter your current password");
|
21 | 25 | String password = (passwordField.getText());
|
| 26 | + passwordField.setBounds(10, 25, 100, 25); |
22 | 27 |
|
| 28 | +// to select feature that user wants to change |
23 | 29 | JLabel lbl = new JLabel("<html>Select what feature<br>you wish to change</html>");
|
24 | 30 | lbl.setVisible(true);
|
| 31 | + lbl.setBounds(10, 25, 100, 25); |
25 | 32 | String[] choices = { "Username","Password", "Email"};
|
26 |
| - final JComboBox<String> cb = new JComboBox<String>(choices); |
| 33 | + final JComboBox<String> cb = new JComboBox<>(choices); |
27 | 34 |
|
| 35 | +// new value of the feature |
28 | 36 | final JTextField newFeatureField = new JTextField("Enter the new value for this feature and click OK");
|
29 |
| - String newFeature = (newFeatureField.getText()); |
| 37 | + newFeatureField.setBounds(10, 25, 100, 25); |
30 | 38 |
|
31 | 39 |
|
| 40 | +// OK button to process |
32 | 41 | JButton btn = new JButton("OK");
|
33 | 42 |
|
34 | 43 | btn.addActionListener(new ActionListener() {
|
@@ -65,10 +74,12 @@ public void actionPerformed(ActionEvent e) {
|
65 | 74 | @Override
|
66 | 75 | public boolean reportChange(String username, String password, String feature, String newFeature) {
|
67 | 76 | UserDatabase db = UserDatabase(accounts);
|
68 |
| - User user = db.getUser(username); |
69 |
| - if (user.PasswordMatch(password) && user.getUsername().equals(username)){ |
70 |
| - user.changeFeature(feature, newFeature); |
71 |
| - return true; |
| 77 | + if (db.UserExists){ |
| 78 | + User user = db.getUser(username); |
| 79 | + if (user.PasswordMatch(password) && user.getUsername().equals(username)){ |
| 80 | + user.changeFeature(feature, newFeature); |
| 81 | + return true; |
| 82 | + } |
72 | 83 | }
|
73 | 84 | return false;
|
74 | 85 | }
|
|
0 commit comments