package gui;
-import javax.swing.*;
-
+import java.awt.Color;
import java.awt.Frame;
-import java.awt.Rectangle;
-import java.util.Vector;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
-import businessLogic.*;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+
+import businessLogic.LoginManager;
+import businessLogic.LoginManagerInterface;
+import domain.Account;
import domain.Owner;
-import domain.RuralHouse;
-import java.awt.event.ActionListener;
-import java.awt.event.ActionEvent;
-import java.awt.Color;
+import javax.swing.JRadioButton;
+import javax.swing.ButtonGroup;
public class LoginGUI extends JFrame {
private JPasswordField passwordField;
private LoginManagerInterface loginManager = new LoginManager();
private JLabel loginFeedback;
-
+ private final ButtonGroup buttonGroup = new ButtonGroup();
public LoginGUI() {
super();
initialize();
JButton loginButton = new JButton("Login");
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
+
jButton_ActionPerformed(arg0);
}
});
}
private void jButton_ActionPerformed(ActionEvent e){
- Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
- if(owner==null){
- loginFeedback.setText("Incorrect username or password");
- }else{
- Vector<RuralHouse> ownerHouseList=null;
- try{
- ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner);
- }catch (Exception e1){
- e1.printStackTrace();
- }
- if(!ownerHouseList.isEmpty()){
+
+ Account acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
+ if (acc.getAdmin()) {
+ this.setVisible(false);
+ Frame a = new AdminMenuGUI();
+ a.setVisible(true);
+ } else {
+ if(acc.getOwner()==null){
+ loginFeedback.setText("Incorrect username or password");
+ }else{
this.setVisible(false);
- Frame a = new IntroduceOffer2GUI(ownerHouseList);
- a.setVisible(true);
+ Frame a = new OwnerMenuGUI(acc.getOwner());
+ a.setVisible(true);
}
- else if(ownerHouseList.isEmpty())
- loginFeedback.setText("Login OK , but no houses in your name");
}
-
+
}
-
} // @jve:decl-index=0:visual-constraint="222,33"