3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
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;
12 import domain.HouseFeatures;
14 import domain.RuralHouse;
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;
26 import businessLogic.HouseManager;
28 public class NewHouseGUI extends JFrame {
33 private static final long serialVersionUID = 1L;
34 private JPanel contentPane;
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;
58 public NewHouseGUI(Owner o) {
59 this.setTitle("New House");
60 setBackground(Color.WHITE);
61 this.getContentPane().setLayout(null);
63 setBounds(100, 100, 500, 583);
64 contentPane = new JPanel();
65 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
66 setContentPane(contentPane);
68 lblCode = new JLabel("House Code:");
69 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
71 Code_f = new JTextField();
72 Code_f.setColumns(10);
74 lblTown = new JLabel("Town:");
75 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
77 Town_f = new JTextField();
78 Town_f.setColumns(10);
80 lblDescription = new JLabel("Description(optional):");
81 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
83 description_f = new JTextField();
84 description_f.setToolTipText("");
85 description_f.setHorizontalAlignment(SwingConstants.LEFT);
86 description_f.setColumns(10);
88 lblKitchen = new JLabel("Kitchens:");
89 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
91 kitchens_f = new JTextField();
92 kitchens_f.setColumns(10);
94 lblRooms = new JLabel("Rooms:");
95 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
97 rooms_f = new JTextField();
98 rooms_f.setColumns(10);
100 lblLivings = new JLabel("Living rooms:");
101 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
103 lRooms_f = new JTextField();
104 lRooms_f.setColumns(10);
106 lblParkings = new JLabel("Parkings:");
107 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
109 parkings_f = new JTextField();
110 parkings_f.setColumns(10);
112 lblBaths = new JLabel("Baths:");
113 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
115 baths_f = new JTextField();
116 baths_f.setColumns(10);
118 btnRegister = new JButton("Register House");
119 btnRegister.addActionListener(new ActionListener() {
120 public void actionPerformed(ActionEvent arg0) {
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()) );
132 catch(NumberFormatException e ){
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()
144 .addComponent(btnRegister))
145 .addGroup(gl_contentPane.createSequentialGroup()
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)
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)
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)
167 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
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)
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)
179 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
180 .addGroup(gl_contentPane.createSequentialGroup()
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))
187 gl_contentPane.setVerticalGroup(
188 gl_contentPane.createParallelGroup(Alignment.LEADING)
189 .addGroup(gl_contentPane.createSequentialGroup()
191 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
192 .addGroup(gl_contentPane.createSequentialGroup()
194 .addComponent(lblDescription)
195 .addPreferredGap(ComponentPlacement.RELATED)
196 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
197 .addGroup(gl_contentPane.createSequentialGroup()
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))
207 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
208 .addComponent(lblLivings)
209 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
211 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
212 .addGroup(gl_contentPane.createSequentialGroup()
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()
221 .addComponent(lblKitchen)))
222 .addPreferredGap(ComponentPlacement.RELATED, 206, Short.MAX_VALUE)
223 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
224 .addGroup(gl_contentPane.createSequentialGroup()
226 .addComponent(lblBaths))
227 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
229 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
230 .addComponent(lblParkings)
231 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
233 .addComponent(btnRegister)
236 contentPane.setLayout(gl_contentPane);