last version with phone regex
authorEneko Pinzolas Murua <kelossus@localhost.localdomain>
Sat, 18 Apr 2015 14:01:54 +0000 (16:01 +0200)
committerEneko Pinzolas Murua <kelossus@localhost.localdomain>
Sat, 18 Apr 2015 14:01:54 +0000 (16:01 +0200)
ruralHouses/src/gui/HouseFeaturesGUI.java
ruralHouses/src/gui/ModifyHouseGUI.java
ruralHouses/src/gui/RequestNewHouseGUI.java

index 0261832..e53b148 100644 (file)
@@ -53,6 +53,7 @@ public class HouseFeaturesGUI extends JFrame {
        private RuralHouse rh;
        private JTextField telIn;
        private int row;
+       private JLabel phoneNum;
 
        /**
         * Create the frame.
@@ -184,7 +185,7 @@ public class HouseFeaturesGUI extends JFrame {
                JLabel lblNewLabel = new JLabel(
                                "Green: Suit your dates. Red: Do not suit your dates");
                lblNewLabel.setEnabled(false);
-               lblNewLabel.setBounds(152, 277, 261, 23);
+               lblNewLabel.setBounds(170, 282, 261, 23);
                contentPane.add(lblNewLabel);
                
                JLabel lblNewLabel_1 = new JLabel("Telephone num:");
@@ -195,6 +196,10 @@ public class HouseFeaturesGUI extends JFrame {
                telIn.setBounds(99, 505, 129, 20);
                contentPane.add(telIn);
                telIn.setColumns(10);
+               
+               phoneNum = new JLabel("");
+               phoneNum.setBounds(215, 255, 201, 15);
+               contentPane.add(phoneNum);
                table.addMouseListener( new MouseAdapter(){                     
                        @Override
                        public void mouseClicked(MouseEvent arg0) {
@@ -240,6 +245,11 @@ public class HouseFeaturesGUI extends JFrame {
        private void jButton_ActionPerformed(ActionEvent arg0) {
                BookingManager bookingM = new BookingManager();
                //RegExp to see if telephone number is correct??TODO
+               if (!telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")){
+                       phoneNum.setText("Wrong phone format");
+               }else {
+                       phoneNum.setText("");
+
                Booking book = null;
                try {
                        if (table.getRowCount()!=0)
@@ -253,5 +263,6 @@ public class HouseFeaturesGUI extends JFrame {
                                        book);
                        confirmWindow.setVisible(true);
                }
+               }
        }
 }
index 106a78b..51815a5 100644 (file)
@@ -47,6 +47,7 @@ public class ModifyHouseGUI extends JFrame {
        private JTextField baths_f;
        private JButton btnConfirm;
        private JComboBox<RuralHouse> houseBox;
+       private  JComboBox<String> comboBox;
        private RuralHouse rh;
 
        /**
@@ -54,7 +55,7 @@ public class ModifyHouseGUI extends JFrame {
         */
        public ModifyHouseGUI(Owner o) {
                this.distric=Districs.longNames();
-               JComboBox<String> comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+               comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
                                this.distric));
                this.getContentPane().setLayout(null);
                owner = o;
@@ -134,8 +135,8 @@ public class ModifyHouseGUI extends JFrame {
                                HouseManager hm = new HouseManager();
 
                                if (hm.registerNewHouse(newRh)) {
-                                       o.getRuralHouses().remove(rh);
-                                       o.getRuralHouses().add(newRh);
+                                       owner.getRuralHouses().remove(rh);
+                                       owner.getRuralHouses().add(newRh);
                                        houseBox.removeItem(rh);
                                        feedback.setText("House properly modified");
                                } else
index 76f182e..7b7ed0a 100644 (file)
@@ -50,14 +50,14 @@ public class RequestNewHouseGUI extends JFrame {
        private JTextField baths_f;
        private JButton btnRegister;
        private AdminManager am;
-       private JComboBox comboBox;
+       private JComboBox<String> comboBox;
 
 
        /**
         * Create the frame.
         */
        public RequestNewHouseGUI(Owner o) {
-               JComboBox<String> comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
+               comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
                                Districs.longNames()));
                am  = new AdminManager();
                this.setTitle("New House");