82f9e0f0aec78aa03a5b392037e93f1bad593eeb
[RRRRHHHH_Code] / ruralHouses / src / gui / DeleteHouseGUI.java
1 package gui;
2
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;
10
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;
19
20 import businessLogic.HouseManager;
21 import businessLogic.HouseManagerInterface;
22 import domain.Owner;
23 import domain.RuralHouse;
24
25 public class DeleteHouseGUI extends JFrame {
26
27         private JPanel contentPane;
28         private Owner owner;
29         private JComboBox comboBox;
30         private JButton btnDelete;
31
32
33         /**
34          * Create the frame.
35          */
36         public DeleteHouseGUI(Owner o) {
37                 this.owner = o;
38                 setBounds(100, 100, 450, 300);
39                 contentPane = new JPanel();
40                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
41                 setContentPane(contentPane);
42         
43                 comboBox = new JComboBox(this.owner.getRuralHouses());
44                 
45
46                 JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
47                 
48                 btnDelete = new JButton("DELETE");
49                 btnDelete.setEnabled(false);
50                 
51                 rdbtnIAmSure.addItemListener(new ItemListener() {
52
53                         @Override
54                         public void itemStateChanged(ItemEvent e) {
55                                 int state = e.getStateChange();
56                                 if (state == ItemEvent.SELECTED){
57                                         btnDelete.setEnabled(true);
58                                 }
59                                 else if (state == ItemEvent.DESELECTED){
60                                         btnDelete.setEnabled(false);
61                                 }
62                         }
63                 });
64                 
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()
71                                                         .addGap(70)
72                                                         .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 332, GroupLayout.PREFERRED_SIZE))
73                                                 .addGroup(gl_contentPane.createSequentialGroup()
74                                                         .addGap(85)
75                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
76                                                                 .addComponent(btnDelete)
77                                                                 .addComponent(rdbtnIAmSure))))
78                                         .addContainerGap(954, Short.MAX_VALUE))
79                 );
80                 gl_contentPane.setVerticalGroup(
81                         gl_contentPane.createParallelGroup(Alignment.LEADING)
82                                 .addGroup(gl_contentPane.createSequentialGroup()
83                                         .addGap(50)
84                                         .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
85                                         .addGap(68)
86                                         .addComponent(rdbtnIAmSure)
87                                         .addGap(47)
88                                         .addComponent(btnDelete)
89                                         .addContainerGap(493, Short.MAX_VALUE))
90                 );
91                 contentPane.setLayout(gl_contentPane);
92                 
93                 btnDelete.addActionListener(new ActionListener() {
94                         public void actionPerformed(ActionEvent arg0) {
95                                 actionListenerButton(arg0);
96                                 
97                         }
98
99                         
100                 });
101         }
102         
103         private void actionListenerButton(ActionEvent e){
104                 RuralHouse toDel = (RuralHouse)comboBox.getSelectedItem();
105                 
106                 HouseManagerInterface hm = new HouseManager();
107                 hm.removeHouse(toDel,this.owner);
108                 comboBox.removeItem(toDel);
109         }
110 }