3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.ItemEvent;
8 import java.awt.event.ItemListener;
9 import java.util.Vector;
11 import javax.swing.JFrame;
12 import javax.swing.JPanel;
13 import javax.swing.border.EmptyBorder;
14 import javax.swing.GroupLayout;
15 import javax.swing.GroupLayout.Alignment;
16 import javax.swing.JComboBox;
17 import javax.swing.JRadioButton;
18 import javax.swing.JButton;
20 import businessLogic.HouseManager;
21 import businessLogic.HouseManagerInterface;
23 import domain.RuralHouse;
25 public class DeleteHouseGUI extends JFrame {
27 private JPanel contentPane;
29 private JComboBox comboBox;
30 private JButton btnDelete;
36 public DeleteHouseGUI(Owner o) {
38 setBounds(100, 100, 450, 300);
39 contentPane = new JPanel();
40 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
41 setContentPane(contentPane);
43 comboBox = new JComboBox(this.owner.getRuralHouses());
46 JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
48 btnDelete = new JButton("DELETE");
49 btnDelete.setEnabled(false);
51 rdbtnIAmSure.addItemListener(new ItemListener() {
54 public void itemStateChanged(ItemEvent e) {
55 int state = e.getStateChange();
56 if (state == ItemEvent.SELECTED){
57 btnDelete.setEnabled(true);
59 else if (state == ItemEvent.DESELECTED){
60 btnDelete.setEnabled(false);
65 GroupLayout gl_contentPane = new GroupLayout(contentPane);
66 gl_contentPane.setHorizontalGroup(
67 gl_contentPane.createParallelGroup(Alignment.LEADING)
68 .addGroup(gl_contentPane.createSequentialGroup()
69 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
70 .addGroup(gl_contentPane.createSequentialGroup()
72 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 332, GroupLayout.PREFERRED_SIZE))
73 .addGroup(gl_contentPane.createSequentialGroup()
75 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
76 .addComponent(btnDelete)
77 .addComponent(rdbtnIAmSure))))
78 .addContainerGap(954, Short.MAX_VALUE))
80 gl_contentPane.setVerticalGroup(
81 gl_contentPane.createParallelGroup(Alignment.LEADING)
82 .addGroup(gl_contentPane.createSequentialGroup()
84 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
86 .addComponent(rdbtnIAmSure)
88 .addComponent(btnDelete)
89 .addContainerGap(493, Short.MAX_VALUE))
91 contentPane.setLayout(gl_contentPane);
93 btnDelete.addActionListener(new ActionListener() {
94 public void actionPerformed(ActionEvent arg0) {
95 actionListenerButton(arg0);
103 private void actionListenerButton(ActionEvent e){
104 RuralHouse toDel = (RuralHouse)comboBox.getSelectedItem();
106 HouseManagerInterface hm = new HouseManager();
107 hm.removeHouse(toDel,this.owner);
108 comboBox.removeItem(toDel);