From 5dd541dad9abed7706e77262901db53a9f71704f Mon Sep 17 00:00:00 2001 From: camjan Date: Wed, 11 Mar 2015 23:59:01 +0100 Subject: [PATCH] GUI added to show list of available houses --- ruralHouses/src/dataAccess/DB4oManager.java | 4 +- .../src/gui/QueryAvailabilityGUI2.java | 24 ++++-- ruralHouses/src/gui/StartWindow.java | 2 +- ruralHouses/src/gui/listOfHousesGUI.java | 78 +++++++++++++++++++ 4 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 ruralHouses/src/gui/listOfHousesGUI.java diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 40fe83c..eff779f 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -110,8 +110,8 @@ public class DB4oManager { try { Owner jon = new Owner("Jon"); Owner alfredo = new Owner("Alfredo"); - jon.addRuralHouse("Ezkio", "Ezkioko etxea", "Ezkio", 3, 3, 3, 3, 3); - jon.addRuralHouse("Eskia", "Eskiatzeko etxea", "Jaca", 4, 4, 4, 4, 4); + jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Ezkio", 3, 3, 3, 3, 3); + jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Jaca", 4, 4, 4, 4, 4); jon.setBankAccount("1349 5677 21 2133567777"); alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Pitillas", 5, 5, 5, 5, 5); diff --git a/ruralHouses/src/gui/QueryAvailabilityGUI2.java b/ruralHouses/src/gui/QueryAvailabilityGUI2.java index b176ef2..d95dcfe 100644 --- a/ruralHouses/src/gui/QueryAvailabilityGUI2.java +++ b/ruralHouses/src/gui/QueryAvailabilityGUI2.java @@ -10,6 +10,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; +import businessLogic.HouseManager; import businessLogic.OfferManager; import com.toedter.calendar.JCalendar; @@ -41,6 +42,7 @@ public class QueryAvailabilityGUI2 extends JFrame { private final JLabel lblNewLabel = new JLabel(""); private final JRadioButton ruralHouseName = new JRadioButton( "Use RuralHouse name"); + private final JRadioButton district = new JRadioButton("Use district name"); private final ButtonGroup buttonGroup = new ButtonGroup(); private final JMenuBar menuBar = new JMenuBar(); private final JMenu mnMoreOptions = new JMenu("Search Options"); @@ -54,24 +56,26 @@ public class QueryAvailabilityGUI2 extends JFrame { private final JTextField nBaths = new JTextField(); private final JLabel lblParkings = new JLabel("Parking slots:"); private final JTextField nParkings = new JTextField(); + private HouseManager houseMan = new HouseManager(); - public QueryAvailabilityGUI2(Vector v) { + public QueryAvailabilityGUI2() { nParkings.setText(""); nParkings.setColumns(10); nBaths.setColumns(10); try { - jbInit(v); + jbInit(); } catch (Exception e) { e.printStackTrace(); } } - private void jbInit(Vector v) throws Exception { + private void jbInit() throws Exception { this.getContentPane().setLayout(null); this.setSize(new Dimension(550, 500)); this.setTitle("Set availability"); - jComboBox1 = new JComboBox(v); + //TODO here we should add the districts of villatripas this is just for testing purposes + jComboBox1 = new JComboBox(this.houseMan.getAllRuralHouses()); jComboBox1.setBounds(new Rectangle(115, 30, 115, 20)); jLabel2.setText("First day :"); jLabel2.setBounds(new Rectangle(20, 134, 85, 25)); @@ -191,12 +195,11 @@ public class QueryAvailabilityGUI2 extends JFrame { getContentPane().add(lblNewLabel); - JRadioButton district = new JRadioButton("Use district name"); - district.setSelected(true); - buttonGroup.add(district); + district.setSelected(true);; district.setBounds(20, 69, 128, 20); getContentPane().add(district); buttonGroup.add(ruralHouseName); + buttonGroup.add(district); ruralHouseName.setBounds(276, 60, 177, 38); district.addItemListener(new ItemListener() { @Override @@ -240,7 +243,12 @@ public class QueryAvailabilityGUI2 extends JFrame { } private void jButton1_actionPerformed(ActionEvent e) { - + if(this.district.isSelected()){ + //show list of houses GUI + } + else if(this.ruralHouseName.isSelected()){ + //show features of specific house + } } private void jButton2_actionPerformed(ActionEvent e) { diff --git a/ruralHouses/src/gui/StartWindow.java b/ruralHouses/src/gui/StartWindow.java index ee3ab51..8d2b019 100644 --- a/ruralHouses/src/gui/StartWindow.java +++ b/ruralHouses/src/gui/StartWindow.java @@ -193,7 +193,7 @@ public class StartWindow extends JFrame { public void actionPerformed(java.awt.event.ActionEvent e) { // C?digo cedido por la universidad //JFrame a = new QueryAvailabilityWindow(); - JFrame a = new QueryAvailabilityGUI(); + JFrame a = new QueryAvailabilityGUI2(); a.setVisible(true); } diff --git a/ruralHouses/src/gui/listOfHousesGUI.java b/ruralHouses/src/gui/listOfHousesGUI.java new file mode 100644 index 0000000..726f738 --- /dev/null +++ b/ruralHouses/src/gui/listOfHousesGUI.java @@ -0,0 +1,78 @@ +package gui; + +import java.awt.BorderLayout; +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JLabel; + +import java.awt.Font; + +import javax.swing.JTextField; +import javax.swing.JScrollPane; + +import java.awt.Rectangle; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +import java.awt.Component; + +import javax.swing.Box; + +public class listOfHousesGUI extends JFrame { + + private JPanel contentPane; + private JTextField textField; + private JTable table; + + /** + * Create the frame. + */ + public listOfHousesGUI() { + try { + init(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void init() throws Exception + { + setBounds(100, 100, 600, 450); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + contentPane.setLayout(null); + + JLabel lblNewLabel = new JLabel("List of available houses in:"); + lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); + lblNewLabel.setBounds(23, 41, 325, 33); + contentPane.add(lblNewLabel); + + textField = new JTextField(); + textField.setEnabled(false); + textField.setEditable(false); + textField.setFont(new Font("Tahoma", Font.PLAIN, 27)); + textField.setBounds(373, 41, 152, 33); + contentPane.add(textField); + textField.setColumns(10); + + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); + scrollPane.setBounds(23, 113, 536, 271); + contentPane.add(scrollPane); + + table = new JTable(); + scrollPane.setViewportView(table); + table.setModel(new DefaultTableModel( + new Object[][] { + }, + new String[] { + "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" + } + )); + } +} -- 2.20.1