bb72996f06f37703f6d3de29014f7c0f7d09c51a
[RRRRHHHH_Code] / ruralHouses / src / gui / NewHouseGUI.java
1 package gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
5
6 import javax.swing.JFrame;
7 import javax.swing.JPanel;
8 import javax.swing.border.EmptyBorder;
9 import javax.swing.GroupLayout;
10 import javax.swing.GroupLayout.Alignment;
11
12 import domain.HouseFeatures;
13 import domain.Owner;
14 import domain.RuralHouse;
15
16 import javax.swing.JLabel;
17 import javax.swing.JTextField;
18 import javax.swing.LayoutStyle.ComponentPlacement;
19 import javax.swing.SwingConstants;
20 import javax.swing.JButton;
21 import java.awt.Color;
22 import java.awt.event.ActionListener;
23 import java.awt.event.ActionEvent;
24 import javax.swing.JTextPane;
25
26 import businessLogic.HouseManager;
27
28 public class NewHouseGUI extends JFrame {
29
30         /**
31          * 
32          */
33         private static final long serialVersionUID = 1L;
34         private JPanel contentPane;
35         private Owner owner;
36         private JLabel lblCode ;
37         private JTextField Code_f;
38         private JLabel lblTown;
39         private JTextField Town_f;
40         private JLabel lblDescription;
41         private JTextField description_f;
42         private JLabel lblKitchen;
43         private JTextField kitchens_f;
44         private JLabel lblRooms;
45         private JTextField rooms_f;
46         private JLabel lblLivings;
47         private JTextField lRooms_f;
48         private JLabel lblParkings;
49         private JTextField parkings_f;
50         private JLabel lblBaths;
51         private JTextField baths_f;
52         private JButton btnRegister;
53
54
55         /**
56          * Create the frame.
57          */
58         public NewHouseGUI(Owner o) {
59                 this.setTitle("New House");
60                 setBackground(Color.WHITE);
61                 this.getContentPane().setLayout(null);
62                 owner = o;
63                 setBounds(100, 100, 500, 583);
64                 contentPane = new JPanel();
65                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
66                 setContentPane(contentPane);
67                 
68                 lblCode = new JLabel("House Code:");
69                 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
70                 
71                 Code_f = new JTextField();
72                 Code_f.setColumns(10);
73                 
74                 lblTown = new JLabel("Town:");
75                 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
76                 
77                 Town_f = new JTextField();
78                 Town_f.setColumns(10);
79                 
80                 lblDescription = new JLabel("Description(optional):");
81                 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
82                 
83                 description_f = new JTextField();
84                 description_f.setToolTipText("");
85                 description_f.setHorizontalAlignment(SwingConstants.LEFT);
86                 description_f.setColumns(10);
87                 
88                 lblKitchen = new JLabel("Kitchens:");
89                 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
90                 
91                 kitchens_f = new JTextField();
92                 kitchens_f.setColumns(10);
93                 
94                 lblRooms = new JLabel("Rooms:");
95                 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
96                 
97                 rooms_f = new JTextField();
98                 rooms_f.setColumns(10);
99                 
100                 lblLivings = new JLabel("Living rooms:");
101                 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
102                 
103                 lRooms_f = new JTextField();
104                 lRooms_f.setColumns(10);
105                 
106                 lblParkings = new JLabel("Parkings:");
107                 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
108                 
109                 parkings_f = new JTextField();
110                 parkings_f.setColumns(10);
111                 
112                 lblBaths = new JLabel("Baths:");
113                 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
114                 
115                 baths_f = new JTextField();
116                 baths_f.setColumns(10);
117                 
118                 btnRegister = new JButton("Register House");
119                 btnRegister.addActionListener(new ActionListener() {
120                         public void actionPerformed(ActionEvent arg0) {
121                                 try {
122                                         HouseManager hm = new HouseManager();
123                                         hm.registerNewHouse(Integer.parseInt(Code_f.getText()),
124                                                                 owner, description_f.getText(),
125                                                                 Town_f.getText() ,Integer.parseInt(rooms_f.getText()),
126                                                                                 Integer.parseInt(kitchens_f.getText()),
127                                                                                 Integer.parseInt(baths_f.getText()),
128                                                                                 Integer.parseInt(lRooms_f.getText()),
129                                                                                 Integer.parseInt(parkings_f.getText()) );
130                                 
131                                 }
132                                 catch(NumberFormatException e ){
133                                         e.printStackTrace();
134                                 }
135                         }
136                 });
137                 GroupLayout gl_contentPane = new GroupLayout(contentPane);
138                 gl_contentPane.setHorizontalGroup(
139                         gl_contentPane.createParallelGroup(Alignment.LEADING)
140                                 .addGroup(gl_contentPane.createSequentialGroup()
141                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
142                                                 .addGroup(gl_contentPane.createSequentialGroup()
143                                                         .addGap(140)
144                                                         .addComponent(btnRegister))
145                                                 .addGroup(gl_contentPane.createSequentialGroup()
146                                                         .addContainerGap()
147                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
148                                                                 .addGroup(gl_contentPane.createSequentialGroup()
149                                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
150                                                                                 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
151                                                                                         .addGroup(gl_contentPane.createSequentialGroup()
152                                                                                                 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
153                                                                                                 .addGap(18)
154                                                                                                 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
155                                                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
156                                                                                                 .addGroup(gl_contentPane.createSequentialGroup()
157                                                                                                         .addComponent(lblLivings)
158                                                                                                         .addGap(18)
159                                                                                                         .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
160                                                                                                 .addGroup(gl_contentPane.createSequentialGroup()
161                                                                                                         .addComponent(lblCode)
162                                                                                                         .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
163                                                                                                         .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
164                                                                                 .addGroup(gl_contentPane.createSequentialGroup()
165                                                                                         .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
166                                                                                         .addGap(18)
167                                                                                         .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
168                                                                         .addGap(29)
169                                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
170                                                                                 .addComponent(lblDescription)
171                                                                                 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
172                                                                 .addGroup(gl_contentPane.createSequentialGroup()
173                                                                         .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
174                                                                         .addGap(18)
175                                                                         .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
176                                                                 .addGroup(gl_contentPane.createSequentialGroup()
177                                                                         .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
178                                                                         .addGap(18)
179                                                                         .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
180                                                 .addGroup(gl_contentPane.createSequentialGroup()
181                                                         .addGap(26)
182                                                         .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
183                                                         .addPreferredGap(ComponentPlacement.UNRELATED)
184                                                         .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
185                                         .addContainerGap(885, Short.MAX_VALUE))
186                 );
187                 gl_contentPane.setVerticalGroup(
188                         gl_contentPane.createParallelGroup(Alignment.LEADING)
189                                 .addGroup(gl_contentPane.createSequentialGroup()
190                                         .addGap(20)
191                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
192                                                 .addGroup(gl_contentPane.createSequentialGroup()
193                                                         .addGap(63)
194                                                         .addComponent(lblDescription)
195                                                         .addPreferredGap(ComponentPlacement.RELATED)
196                                                         .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
197                                                 .addGroup(gl_contentPane.createSequentialGroup()
198                                                         .addGap(60)
199                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
200                                                                 .addComponent(lblCode)
201                                                                 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
202                                                         .addPreferredGap(ComponentPlacement.UNRELATED)
203                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
204                                                                 .addComponent(Town_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
205                                                                 .addComponent(lblTown))
206                                                         .addGap(18)
207                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
208                                                                 .addComponent(lblLivings)
209                                                                 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
210                                         .addGap(63)
211                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
212                                                 .addGroup(gl_contentPane.createSequentialGroup()
213                                                         .addGap(3)
214                                                         .addComponent(lblRooms))
215                                                 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
216                                         .addPreferredGap(ComponentPlacement.RELATED)
217                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
218                                                 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
219                                                 .addGroup(gl_contentPane.createSequentialGroup()
220                                                         .addGap(3)
221                                                         .addComponent(lblKitchen)))
222                                         .addPreferredGap(ComponentPlacement.RELATED, 206, Short.MAX_VALUE)
223                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
224                                                 .addGroup(gl_contentPane.createSequentialGroup()
225                                                         .addGap(3)
226                                                         .addComponent(lblBaths))
227                                                 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
228                                         .addGap(45)
229                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
230                                                 .addComponent(lblParkings)
231                                                 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
232                                         .addGap(88)
233                                         .addComponent(btnRegister)
234                                         .addGap(54))
235                 );
236                 contentPane.setLayout(gl_contentPane);
237         }
238 }