Login GUI completed
[RRRRHHHH_Code] / ruralHouses / src / gui / IntroduceOfferGUI.java
1 package gui;
2
3 import javax.swing.*;
4
5 import java.awt.Frame;
6 import java.awt.Rectangle;
7 import java.util.Vector;
8
9 import businessLogic.ApplicationFacadeInterface;
10 import domain.Owner;
11 import domain.RuralHouse;
12
13 import java.awt.event.ActionListener;
14 import java.awt.event.ActionEvent;
15
16 public class IntroduceOfferGUI extends JFrame {
17
18         private static final long serialVersionUID = 1L;
19         private JPanel jContentPane = null;
20         private JTextField usernameField;
21         private JPasswordField passwordField;
22         private JTextField textField;
23         private LoginManager loginManager = new LoginManagerInterface();
24
25         public IntroduceOfferGUI() {
26                 super();
27                 initialize();
28         }
29
30         private void initialize() {
31                 this.setSize(449, 293);
32                 this.setContentPane(getJContentPane());
33                 this.setTitle("Login");
34
35         }
36
37         private JPanel getJContentPane() {
38                 if (jContentPane == null) {
39                         jContentPane = new JPanel();
40                         jContentPane.setLayout(null);
41                         
42                         JLabel usernameTag = new JLabel("Username:");
43                         usernameTag.setBounds(56, 67, 104, 20);
44                         jContentPane.add(usernameTag);
45                         
46                         JLabel passwordTag = new JLabel("Password:");
47                         passwordTag.setBounds(56, 132, 104, 15);
48                         jContentPane.add(passwordTag);
49                         
50                         usernameField = new JTextField();
51                         usernameField.setBounds(208, 68, 114, 19);
52                         jContentPane.add(usernameField);
53                         usernameField.setColumns(10);
54                         
55                         passwordField = new JPasswordField();
56                         passwordField.setBounds(208, 129, 114, 18);
57                         jContentPane.add(passwordField);
58                         
59                         JButton loginButton = new JButton("Login");
60                         loginButton.addActionListener(new ActionListener() {
61                                 public void actionPerformed(ActionEvent arg0) {
62                                         Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword());
63                                         if(owner==null){
64                                                 textField.setText("Incorrect username or password");
65                                         }else{
66                                                 Vector<RuralHouse> ownerHouseList=null;
67                                                 try{
68                                                         ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner);
69                                                 }catch (Exception e){
70                                                         e.printStackTrace();
71                                                 }
72                                                 if(!ownerHouseList.isEmpty()){
73                                                         Frame a = new IntroduceOffer2GUI(ownerHouseList);
74                                                         a.setVisible(true);
75                                                 }
76                                                 else if(ownerHouseList.isEmpty())
77                                                         textField.setText("Login OK , but no houses in your name");
78                                         }
79
80                                 }
81                         });
82                         loginButton.setBounds(151, 178, 117, 25);
83                         jContentPane.add(loginButton);
84                         
85                         textField = new JTextField();
86                         textField.setBounds(127, 227, 185, 26);
87                         jContentPane.add(textField);
88                         textField.setColumns(10);
89                 }
90                 return jContentPane;
91         }
92 } // @jve:decl-index=0:visual-constraint="222,33"