cleaning
[RRRRHHHH_Code] / ruralHouses / src / gui / OwnerRegistrationGUI.java
1 package gui;
2
3 import java.awt.Color;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.rmi.Naming;
7 import java.rmi.RemoteException;
8
9 import javax.swing.JButton;
10 import javax.swing.JFrame;
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JTextField;
14 import javax.swing.border.EmptyBorder;
15
16 import common.AdminInterface;
17
18 import configuration.___IntNames;
19 import domain.Owner;
20
21 public class OwnerRegistrationGUI extends JFrame {
22
23         /**
24          * 
25          */
26         private static final long serialVersionUID = 1L;
27         private JPanel panel;
28         private JTextField nameField;
29         private JTextField userNameField;
30         private AdminInterface am = null;
31         private JTextField passField;
32         private JTextField bank1Field;
33         private JTextField bank2Field;
34         private JTextField bank3Field;
35         private JTextField bank4Field;
36         private JTextField emailField;
37         private JLabel lblWhenAcceptedYou;
38         private JLabel feedback;
39
40         /**
41          * Create the frame.
42          */
43         public OwnerRegistrationGUI() {
44                 
45                 try {
46                         am = (AdminInterface) Naming
47                                         .lookup(___IntNames.AdminManager);
48                 } catch (Exception e1) {
49                         System.out.println("Error accessing remote authentication: "
50                                         + e1.toString());
51                 }
52                 setTitle("Owner registration");
53                 setBounds(100, 100, 500, 400);
54                 panel = new JPanel();
55                 panel.setBorder(new EmptyBorder(5, 5, 5, 5));
56                 setContentPane(panel);
57                 panel.setLayout(null);
58
59                 JLabel nameLb = new JLabel("Name:");
60                 nameLb.setBounds(37, 45, 46, 14);
61                 panel.add(nameLb);
62
63                 nameField = new JTextField();
64                 nameField.setBounds(147, 42, 86, 20);
65                 panel.add(nameField);
66                 nameField.setColumns(10);
67
68                 JLabel lblUsername = new JLabel("Username:");
69                 lblUsername.setBounds(37, 212, 69, 14);
70                 panel.add(lblUsername);
71
72                 userNameField = new JTextField();
73                 userNameField.setBounds(147, 209, 86, 20);
74                 panel.add(userNameField);
75                 userNameField.setColumns(10);
76
77                 JLabel lblPassword = new JLabel("Password:");
78                 lblPassword.setBounds(37, 258, 69, 14);
79                 panel.add(lblPassword);
80
81                 passField = new JTextField();
82                 passField.setBounds(147, 255, 86, 20);
83                 panel.add(passField);
84                 passField.setColumns(10);
85
86                 JLabel lblBankAccount = new JLabel("Bank account:");
87                 lblBankAccount.setBounds(37, 94, 69, 14);
88                 panel.add(lblBankAccount);
89
90                 bank1Field = new JTextField();
91                 bank1Field.setBounds(147, 91, 61, 20);
92                 panel.add(bank1Field);
93
94                 bank2Field = new JTextField();
95                 bank2Field.setBounds(218, 91, 61, 20);
96                 panel.add(bank2Field);
97
98                 bank3Field = new JTextField();
99                 bank3Field.setBounds(289, 91, 32, 20);
100                 panel.add(bank3Field);
101
102                 bank4Field = new JTextField();
103                 bank4Field.setBounds(331, 91, 117, 20);
104                 panel.add(bank4Field);
105
106                 JButton btnSendRegistrationRequest = new JButton(
107                                 "Send registration request");
108                 btnSendRegistrationRequest.setBounds(127, 316, 194, 23);
109                 btnSendRegistrationRequest.addActionListener(new ActionListener() {
110                         public void actionPerformed(ActionEvent arg0) {
111
112                                 jButton_ActionPerformed(arg0);
113                         }
114                 });
115
116                 panel.add(btnSendRegistrationRequest);
117
118                 JLabel lblEmail = new JLabel("E-mail:");
119                 lblEmail.setBounds(37, 155, 46, 14);
120                 panel.add(lblEmail);
121
122                 emailField = new JTextField();
123                 emailField.setBounds(147, 152, 148, 20);
124                 panel.add(emailField);
125                 emailField.setColumns(10);
126
127                 lblWhenAcceptedYou = new JLabel(
128                                 "When accepted you will receive an e-mail");
129                 lblWhenAcceptedYou.setForeground(Color.GREEN);
130                 lblWhenAcceptedYou.setBounds(127, 291, 214, 14);
131                 panel.add(lblWhenAcceptedYou);
132
133                 feedback = new JLabel("");
134                 feedback.setForeground(Color.RED);
135                 feedback.setEnabled(false);
136                 feedback.setBounds(127, 344, 214, 20);
137                 panel.add(feedback);
138         }
139
140         private void jButton_ActionPerformed(ActionEvent e) {
141
142                 Owner own = new Owner(this.nameField.getText(),
143                                 this.bank1Field.getText() + " " + this.bank2Field.getText()
144                                                 + " " + this.bank3Field.getText() + " "
145                                                 + this.bank4Field.getText(), this.emailField.getText());
146
147
148                 try {
149                         if (this.am.addAccountRequest(this.userNameField.getText(),
150                                         this.passField.getText(), own)) {
151                                 this.am.saveInstance();
152                                 this.feedback.setText("Request sended");
153                         } else {
154                                 this.feedback.setText("Can't send the request");
155                         }
156                 } catch (RemoteException e1) {
157                         // TODO Auto-generated catch block
158                         e1.printStackTrace();
159                 }
160
161         }
162 }