|
@@ -3,6 +3,8 @@ |
3 |
3 |
|
import java.awt.BorderLayout; |
4 |
4 |
|
import java.awt.EventQueue; |
5 |
5 |
|
|
|
6 |
+ |
import domain.*; |
|
7 |
+ |
|
6 |
8 |
|
import javax.swing.JFrame; |
7 |
9 |
|
import javax.swing.JPanel; |
8 |
10 |
|
import javax.swing.border.EmptyBorder; |
|
@@ -19,6 +21,10 @@ |
19 |
21 |
|
import javax.swing.table.DefaultTableModel; |
20 |
22 |
|
|
21 |
23 |
|
import java.awt.Component; |
|
24 |
+ |
import java.sql.Date; |
|
25 |
+ |
import java.util.Enumeration; |
|
26 |
+ |
import java.util.LinkedList; |
|
27 |
+ |
import java.util.Vector; |
22 |
28 |
|
|
23 |
29 |
|
import javax.swing.Box; |
24 |
30 |
|
|
|
@@ -27,31 +33,31 @@ |
27 |
33 |
|
private JPanel contentPane; |
28 |
34 |
|
private JTextField textField; |
29 |
35 |
|
private JTable table; |
|
36 |
+ |
private DefaultTableModel tableModel; |
30 |
37 |
|
|
31 |
38 |
|
/** |
32 |
39 |
|
* Create the frame. |
33 |
40 |
|
*/ |
34 |
|
- |
public listOfHousesGUI() { |
|
41 |
+ |
public listOfHousesGUI(Vector<RuralHouse> houses) { |
35 |
42 |
|
try { |
36 |
|
- |
init(); |
|
43 |
+ |
init(houses); |
37 |
44 |
|
} catch (Exception e) { |
38 |
45 |
|
e.printStackTrace(); |
39 |
46 |
|
} |
40 |
47 |
|
} |
41 |
|
- |
|
42 |
|
- |
private void init() throws Exception |
43 |
|
- |
{ |
|
48 |
+ |
|
|
49 |
+ |
private void init(Vector<RuralHouse> houses) throws Exception { |
44 |
50 |
|
setBounds(100, 100, 600, 450); |
45 |
51 |
|
contentPane = new JPanel(); |
46 |
52 |
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
47 |
53 |
|
setContentPane(contentPane); |
48 |
54 |
|
contentPane.setLayout(null); |
49 |
|
- |
|
|
55 |
+ |
|
50 |
56 |
|
JLabel lblNewLabel = new JLabel("List of available houses in:"); |
51 |
57 |
|
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); |
52 |
58 |
|
lblNewLabel.setBounds(23, 41, 325, 33); |
53 |
59 |
|
contentPane.add(lblNewLabel); |
54 |
|
- |
|
|
60 |
+ |
|
55 |
61 |
|
textField = new JTextField(); |
56 |
62 |
|
textField.setEnabled(false); |
57 |
63 |
|
textField.setEditable(false); |
|
@@ -59,20 +65,38 @@ |
59 |
65 |
|
textField.setBounds(373, 41, 152, 33); |
60 |
66 |
|
contentPane.add(textField); |
61 |
67 |
|
textField.setColumns(10); |
62 |
|
- |
|
|
68 |
+ |
if (houses.isEmpty()) |
|
69 |
+ |
textField.setText("No houses Matching"); |
|
70 |
+ |
else |
|
71 |
+ |
textField.setText(houses.get(0).getTown()); |
63 |
72 |
|
JScrollPane scrollPane = new JScrollPane(); |
64 |
73 |
|
scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); |
65 |
74 |
|
scrollPane.setBounds(23, 113, 536, 271); |
66 |
75 |
|
contentPane.add(scrollPane); |
67 |
|
- |
|
|
76 |
+ |
|
68 |
77 |
|
table = new JTable(); |
69 |
78 |
|
scrollPane.setViewportView(table); |
70 |
|
- |
table.setModel(new DefaultTableModel( |
71 |
|
- |
new Object[][] { |
72 |
|
- |
}, |
73 |
|
- |
new String[] { |
74 |
|
- |
"House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" |
75 |
|
- |
} |
76 |
|
- |
)); |
77 |
|
- |
} |
|
79 |
+ |
tableModel = new DefaultTableModel(null, new String[] { |
|
80 |
+ |
"House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", |
|
81 |
+ |
"Livings" }); |
|
82 |
+ |
//Maybe there is a better way to avoid interaction. |
|
83 |
+ |
table.setEnabled(false); |
|
84 |
+ |
table.setModel(tableModel); |
|
85 |
+ |
Enumeration<RuralHouse> en = houses.elements(); |
|
86 |
+ |
RuralHouse rh; |
|
87 |
+ |
|
|
88 |
+ |
while (en.hasMoreElements()) { |
|
89 |
+ |
rh = en.nextElement(); |
|
90 |
+ |
Vector<Object> row = new Vector<Object>(); |
|
91 |
+ |
row.add(rh.getHouseName()); |
|
92 |
+ |
row.add(rh.getFeatures().getnRooms()); |
|
93 |
+ |
row.add(rh.getFeatures().getnKitchens()); |
|
94 |
+ |
row.add(rh.getFeatures().getnBaths()); |
|
95 |
+ |
row.add(rh.getFeatures().getnParkings()); |
|
96 |
+ |
row.add(rh.getFeatures().getnLivings()); |
|
97 |
+ |
System.out.println(rh.getFeatures().getnLivings()); |
|
98 |
+ |
tableModel.addRow(row); |
|
99 |
+ |
} |
|
100 |
+ |
|
|
101 |
+ |
} |
78 |
102 |
|
} |