Possibility of registering new owners added
[RRRRHHHH_Code] / ruralHouses / src / gui / LoginGUI.java
1 package gui;
2
3 import java.awt.Color;
4 import java.awt.Frame;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7
8 import javax.swing.JButton;
9 import javax.swing.JFrame;
10 import javax.swing.JLabel;
11 import javax.swing.JPanel;
12 import javax.swing.JPasswordField;
13 import javax.swing.JTextField;
14 import javax.swing.SwingConstants;
15
16 import businessLogic.LoginManager;
17 import businessLogic.LoginManagerInterface;
18 import domain.Account;
19
20 public class LoginGUI extends JFrame {
21
22         private static final long serialVersionUID= 1L;
23         private JPanel jContentPane = null;
24         private JTextField usernameField;
25         private JPasswordField passwordField;
26         private LoginManagerInterface loginManager = new LoginManager();
27         private JLabel loginFeedback;
28         private JButton btnRegister;
29         public LoginGUI() {
30                 super();
31                 initialize();
32         }
33
34         private void initialize() {
35                 this.setSize(449, 293);
36                 this.setContentPane(getJContentPane());
37                 this.setTitle("Login");
38
39         }
40
41         private JPanel getJContentPane() {
42                 if (jContentPane == null) {
43                         jContentPane = new JPanel();
44                         jContentPane.setLayout(null);
45                         
46                         JLabel usernameTag = new JLabel("Username:");
47                         usernameTag.setBounds(56, 67, 104, 20);
48                         jContentPane.add(usernameTag);
49                         
50                         JLabel passwordTag = new JLabel("Password:");
51                         passwordTag.setBounds(56, 132, 104, 15);
52                         jContentPane.add(passwordTag);
53                         
54                         usernameField = new JTextField();
55                         usernameField.setBounds(202, 65, 133, 25);
56                         jContentPane.add(usernameField);
57                         usernameField.setColumns(10);
58                         
59                         passwordField = new JPasswordField();
60                         passwordField.setBounds(202, 122, 133, 25);
61                         jContentPane.add(passwordField);
62                         
63                         JButton loginButton = new JButton("Login");
64                         loginButton.addActionListener(new ActionListener() {
65                                 public void actionPerformed(ActionEvent arg0) {
66
67                                 jButton_ActionPerformed(arg0);  
68                                 }                                       
69                         });
70                         loginButton.setBounds(95, 179, 117, 25);
71                         jContentPane.add(loginButton);
72                         
73                         loginFeedback = new JLabel("");
74                         loginFeedback.setForeground(Color.RED);
75                         loginFeedback.setHorizontalAlignment(SwingConstants.CENTER);
76                         loginFeedback.setBounds(83, 216, 269, 25);
77                         jContentPane.add(loginFeedback);
78                         
79                         btnRegister = new JButton("Register");
80                         btnRegister.setBounds(222, 180, 113, 23);
81                         btnRegister.addActionListener(new ActionListener() {
82                                 public void actionPerformed(ActionEvent arg0) {
83
84                                 jButton_ActionPerformed2(arg0); 
85                                 }                                       
86                         });
87                         jContentPane.add(btnRegister);
88                 }
89                 return jContentPane;
90         }
91         private void jButton_ActionPerformed2(ActionEvent e){
92                 
93                 
94                         this.setVisible(false);
95                         Frame a = new OwnerRegistrationGUI();
96                         a.setVisible(true);
97                 
98                 
99         }
100         private void jButton_ActionPerformed(ActionEvent e){
101                         
102                 Account acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
103                 if (acc == null) loginFeedback.setText("Incorrect username or password");
104                 else if( acc.getAdmin()) {
105                         this.setVisible(false);
106                         Frame a = new AdminMenuGUI();
107                         a.setVisible(true);
108                 } else {
109                         if(acc.getOwner()==null){
110                                 loginFeedback.setText("Incorrect username or password");
111                         }else{
112                                 this.setVisible(false);
113                                 Frame a = new OwnerMenuGUI(acc.getOwner());
114                                 a.setVisible(true);             
115                         }
116                 }
117                 
118         }
119 }  // @jve:decl-index=0:visual-constraint="222,33"
120