The code for different owner operations mostly implemented
[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.*;
10 import domain.Owner;
11 import domain.RuralHouse;
12
13 import java.awt.event.ActionListener;
14 import java.awt.event.ActionEvent;
15 import java.awt.Color;
16
17 public class IntroduceOfferGUI extends JFrame {
18
19         private static final long serialVersionUID= 1L;
20         private JPanel jContentPane = null;
21         private JTextField usernameField;
22         private JPasswordField passwordField;
23         private LoginManagerInterface loginManager = new LoginManager();
24         private JLabel loginFeedback;
25
26         public IntroduceOfferGUI() {
27                 super();
28                 initialize();
29         }
30
31         private void initialize() {
32                 this.setSize(449, 293);
33                 this.setContentPane(getJContentPane());
34                 this.setTitle("Login");
35
36         }
37
38         private JPanel getJContentPane() {
39                 if (jContentPane == null) {
40                         jContentPane = new JPanel();
41                         jContentPane.setLayout(null);
42                         
43                         JLabel usernameTag = new JLabel("Username:");
44                         usernameTag.setBounds(56, 67, 104, 20);
45                         jContentPane.add(usernameTag);
46                         
47                         JLabel passwordTag = new JLabel("Password:");
48                         passwordTag.setBounds(56, 132, 104, 15);
49                         jContentPane.add(passwordTag);
50                         
51                         usernameField = new JTextField();
52                         usernameField.setBounds(202, 65, 133, 25);
53                         jContentPane.add(usernameField);
54                         usernameField.setColumns(10);
55                         
56                         passwordField = new JPasswordField();
57                         passwordField.setBounds(202, 122, 133, 25);
58                         jContentPane.add(passwordField);
59                         
60                         JButton loginButton = new JButton("Login");
61                         loginButton.addActionListener(new ActionListener() {
62                                 public void actionPerformed(ActionEvent arg0) {
63                                         Owner owner = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
64                                         if(owner==null){
65                                                 loginFeedback.setText("Incorrect username or password");
66                                         }else{
67                                                 Vector<RuralHouse> ownerHouseList=null;
68                                                 try{
69                                                         ownerHouseList = StartWindow.getBusinessLogic().getRuralHouses(owner);
70                                                 }catch (Exception e){
71                                                         e.printStackTrace();
72                                                 }
73                                                 if(!ownerHouseList.isEmpty()){
74                                                         Frame a = new IntroduceOffer2GUI(ownerHouseList);       
75                                                         a.setVisible(true);
76                                                 }
77                                                 else if(ownerHouseList.isEmpty())
78                                                         loginFeedback.setText("Login OK , but no houses in your name");
79                                         }
80
81                                 }
82                         });
83                         loginButton.setBounds(164, 179, 117, 25);
84                         jContentPane.add(loginButton);
85                         
86                         loginFeedback = new JLabel("");
87                         loginFeedback.setForeground(Color.RED);
88                         loginFeedback.setHorizontalAlignment(SwingConstants.CENTER);
89                         loginFeedback.setBounds(83, 216, 269, 25);
90                         jContentPane.add(loginFeedback);
91                 }
92                 return jContentPane;
93         }
94
95
96 }  // @jve:decl-index=0:visual-constraint="222,33"
97