Skip to content

Commit bbd37a5

Browse files
committed
Changed the layout of th UI
1 parent cc3558b commit bbd37a5

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/main/java/UserModificationUI.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,42 @@
22
* Provides the UI elements
33
*/
44
import javax.swing.*;
5-
import java.awt.GridLayout;
5+
import java.awt.*;
66
import java.awt.event.ActionEvent;
77
import java.awt.event.ActionListener;
88

99
public class UserModificationUI implements ChangeController{
1010
private JLabel label;
1111
public UserModificationUI() {
1212
final JFrame frame = new JFrame();
13-
frame.setSize(1200, 100);
13+
frame.setSize(500, 300);
14+
1415
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
15-
frame.setLayout(new GridLayout());
16+
frame.setLayout(new FlowLayout());
1617

18+
// Field for username
1719
final JTextField usernameField = new JTextField("Enter your current username");
20+
usernameField.setBounds(10, 25, 100, 25);
1821
String username = (usernameField.getText());
1922

23+
// Field for password
2024
final JTextField passwordField = new JTextField("Enter your current password");
2125
String password = (passwordField.getText());
26+
passwordField.setBounds(10, 25, 100, 25);
2227

28+
// to select feature that user wants to change
2329
JLabel lbl = new JLabel("<html>Select what feature<br>you wish to change</html>");
2430
lbl.setVisible(true);
31+
lbl.setBounds(10, 25, 100, 25);
2532
String[] choices = { "Username","Password", "Email"};
26-
final JComboBox<String> cb = new JComboBox<String>(choices);
33+
final JComboBox<String> cb = new JComboBox<>(choices);
2734

35+
// new value of the feature
2836
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);
3038

3139

40+
// OK button to process
3241
JButton btn = new JButton("OK");
3342

3443
btn.addActionListener(new ActionListener() {
@@ -65,10 +74,12 @@ public void actionPerformed(ActionEvent e) {
6574
@Override
6675
public boolean reportChange(String username, String password, String feature, String newFeature) {
6776
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+
}
7283
}
7384
return false;
7485
}

0 commit comments

Comments
 (0)