Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard

Diff Revisions cff7b0 ... vs 3e4f7e ... for ruralHouses/src/gui/listOfHousesGUI.java

Diff revisions: vs.
  @@ -21,6 +21,8 @@
21 21 import javax.swing.table.DefaultTableModel;
22 22
23 23 import java.awt.Component;
24 + import java.awt.event.MouseAdapter;
25 + import java.awt.event.MouseEvent;
24 26 import java.sql.Date;
25 27 import java.util.Enumeration;
26 28 import java.util.LinkedList;
  @@ -33,19 +35,20 @@
33 35 private JPanel contentPane;
34 36 private JTable table;
35 37 private DefaultTableModel tableModel;
36 -
37 - /**
38 + private Vector<RuralHouse> houses;
39 + /**
38 40 * Create the frame.
39 41 */
40 - public listOfHousesGUI(Vector<RuralHouse> houses) {
42 + public listOfHousesGUI(Vector<RuralHouse> rhs) {
41 43 try {
42 - init(houses);
44 + this.houses=rhs;
45 + init();
43 46 } catch (Exception e) {
44 47 e.printStackTrace();
45 48 }
46 49 }
47 50
48 - private void init(Vector<RuralHouse> houses) throws Exception {
51 + private void init() throws Exception {
49 52 setBounds(100, 100, 600, 450);
50 53 contentPane = new JPanel();
51 54 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  @@ -65,17 +68,31 @@
65 68 scrollPane.setBounds(23, 113, 536, 271);
66 69 contentPane.add(scrollPane);
67 70
68 - table = new JTable();
71 + JTable table = new JTable() {
72 + private static final long serialVersionUID = 1L;
73 +
74 + public boolean isCellEditable(int row, int column) {
75 + return false;
76 + };
77 + };
69 78 scrollPane.setViewportView(table);
70 79 tableModel = new DefaultTableModel(null, new String[] {
71 80 "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
72 81 "Livings" });
82 +
73 83 //Maybe there is a better way to avoid interaction.
74 84 //table.setEnabled(false);
75 85 table.setModel(tableModel);
76 86 Enumeration<RuralHouse> en = houses.elements();
77 87 RuralHouse rh;
78 -
88 + table.addMouseListener( new MouseAdapter(){
89 + @Override
90 + public void mouseClicked(MouseEvent arg0) {
91 + int row = table.getSelectedRow();
92 + HouseFeaturesGUI feat = new HouseFeaturesGUI(houses.get(row),null,null);
93 + feat.setVisible(true);
94 + }
95 + });
79 96 while (en.hasMoreElements()) {
80 97 rh = en.nextElement();
81 98 Vector<Object> row = new Vector<Object>();