package gui; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.LayoutStyle.ComponentPlacement; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import businessLogic.HouseManager; import domain.HouseFeatures; import domain.Owner; import domain.RuralHouse; public class ModifyHouseGUI extends JFrame { /** * */ private static final long serialVersionUID = 1L; private JPanel contentPane; private Owner owner; private JLabel lblDistrict; private JTextField District_f; private JLabel feedback; private JLabel lblDescription; private JTextField description_f; private JLabel lblKitchen; private JTextField kitchens_f; private JLabel lblRooms; private JTextField rooms_f; private JLabel lblLivings; private JTextField lRooms_f; private JLabel lblParkings; private JTextField parkings_f; private JLabel lblBaths; private JTextField baths_f; private JButton btnConfirm; private JComboBox houseBox; private RuralHouse rh; /** * Create the frame. */ public ModifyHouseGUI(Owner o) { this.getContentPane().setLayout(null); owner = o; setBounds(100, 100, 500, 583); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); JLabel lblCode = new JLabel("House Name:"); lblCode.setBounds(15, 88, 64, 14); lblCode.setHorizontalAlignment(SwingConstants.RIGHT); lblDistrict = new JLabel("District:"); lblDistrict.setBounds(39, 119, 70, 14); lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT); District_f = new JTextField(); District_f.setBounds(127, 116, 86, 20); District_f.setColumns(10); lblDescription = new JLabel("Description:"); lblDescription.setBounds(231, 88, 90, 14); lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); description_f = new JTextField(); description_f.setBounds(241, 113, 178, 129); description_f.setColumns(10); lblKitchen = new JLabel("Kitchens:"); lblKitchen.setBounds(230, 316, 70, 14); lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT); kitchens_f = new JTextField(); kitchens_f.setBounds(318, 313, 86, 20); kitchens_f.setColumns(10); lblRooms = new JLabel("Rooms:"); lblRooms.setBounds(39, 316, 70, 14); lblRooms.setHorizontalAlignment(SwingConstants.RIGHT); rooms_f = new JTextField(); rooms_f.setBounds(127, 313, 86, 20); rooms_f.setColumns(10); lblLivings = new JLabel("Living rooms:"); lblLivings.setBounds(237, 354, 63, 14); lblLivings.setHorizontalAlignment(SwingConstants.RIGHT); lRooms_f = new JTextField(); lRooms_f.setBounds(318, 351, 86, 20); lRooms_f.setColumns(10); lblParkings = new JLabel("Parkings:"); lblParkings.setBounds(39, 404, 70, 14); lblParkings.setHorizontalAlignment(SwingConstants.RIGHT); parkings_f = new JTextField(); parkings_f.setBounds(127, 401, 86, 20); parkings_f.setColumns(10); lblBaths = new JLabel("Baths:"); lblBaths.setBounds(39, 354, 70, 14); lblBaths.setHorizontalAlignment(SwingConstants.RIGHT); baths_f = new JTextField(); baths_f.setBounds(127, 351, 86, 20); baths_f.setColumns(10); btnConfirm = new JButton("Confirm"); btnConfirm.setBounds(145, 462, 69, 23); btnConfirm.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { RuralHouse newRh = new RuralHouse(rh.getHouseName(), owner, description_f.getText(), District_f.getText(), new HouseFeatures(new Integer(rooms_f.getText()), new Integer(kitchens_f.getText()), new Integer( baths_f.getText()), new Integer( lRooms_f.getText()), new Integer( parkings_f.getText()))); HouseManager hm = new HouseManager(); if (hm.registerNewHouse(newRh)) { feedback.setText("House properly modified"); } else feedback.setText("Imposible to modify the house"); } }); houseBox = new JComboBox(o.getRuralHouses()); if (!o.getRuralHouses().isEmpty()) { rh = (RuralHouse) houseBox.getSelectedItem(); District_f.setText(rh.getDistrict()); description_f.setText(rh.getDescription()); kitchens_f.setText(Integer .toString(rh.getFeatures().getnKitchens())); rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); parkings_f.setText(Integer .toString(rh.getFeatures().getnParkings())); baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); houseBox.setBounds(89, 85, 124, 20); }else{ feedback.setText("Not available houses"); } houseBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { rh = (RuralHouse) houseBox.getSelectedItem(); District_f.setText(rh.getDistrict()); description_f.setText(rh.getDescription()); kitchens_f.setText(Integer.toString(rh.getFeatures() .getnKitchens())); rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); lRooms_f.setText(Integer.toString(rh.getFeatures() .getnLivings())); parkings_f.setText(Integer.toString(rh.getFeatures() .getnParkings())); baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); } }); contentPane.setLayout(null); contentPane.add(lblParkings); contentPane.add(parkings_f); contentPane.add(lblRooms); contentPane.add(rooms_f); contentPane.add(lblCode); contentPane.add(houseBox); contentPane.add(lblBaths); contentPane.add(baths_f); contentPane.add(lblDistrict); contentPane.add(District_f); contentPane.add(lblLivings); contentPane.add(lRooms_f); contentPane.add(lblKitchen); contentPane.add(kitchens_f); contentPane.add(description_f); contentPane.add(lblDescription); contentPane.add(btnConfirm); feedback = new JLabel(""); feedback.setBounds(189, 510, 195, 23); contentPane.add(feedback); } }