imports leaned
[RRRRHHHH_Code] / ruralHouses / src / gui / RequestDeleteHouseGUI.java
1 package gui;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.awt.event.ItemEvent;
6 import java.awt.event.ItemListener;
7
8 import javax.swing.GroupLayout;
9 import javax.swing.GroupLayout.Alignment;
10 import javax.swing.JButton;
11 import javax.swing.JComboBox;
12 import javax.swing.JFrame;
13 import javax.swing.JPanel;
14 import javax.swing.JRadioButton;
15 import javax.swing.border.EmptyBorder;
16
17 import businessLogic.AdminManager;
18 import domain.Owner;
19 import domain.RuralHouse;
20
21 public class RequestDeleteHouseGUI extends JFrame {
22
23         private JPanel contentPane;
24         private Owner owner;
25         private JComboBox comboBox;
26         private JButton btnDelete;
27         private AdminManager am;
28
29         /**
30          * Create the frame.
31          */
32         public RequestDeleteHouseGUI(Owner o) {
33                 am  = new AdminManager();
34                 this.owner = o;
35                 setBounds(100, 100, 450, 300);
36                 contentPane = new JPanel();
37                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
38                 setContentPane(contentPane);
39         
40                 comboBox = new JComboBox(this.owner.getRuralHouses());
41                 
42
43                 JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
44                 
45                 btnDelete = new JButton("REQUEST");
46                 btnDelete.setEnabled(false);
47                 
48                 rdbtnIAmSure.addItemListener(new ItemListener() {
49
50                         @Override
51                         public void itemStateChanged(ItemEvent e) {
52                                 int state = e.getStateChange();
53                                 if (state == ItemEvent.SELECTED){
54                                         btnDelete.setEnabled(true);
55                                 }
56                                 else if (state == ItemEvent.DESELECTED){
57                                         btnDelete.setEnabled(false);
58                                 }
59                         }
60                 });
61                 
62                 GroupLayout gl_contentPane = new GroupLayout(contentPane);
63                 gl_contentPane.setHorizontalGroup(
64                         gl_contentPane.createParallelGroup(Alignment.LEADING)
65                                 .addGroup(gl_contentPane.createSequentialGroup()
66                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
67                                                 .addGroup(gl_contentPane.createSequentialGroup()
68                                                         .addGap(70)
69                                                         .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 332, GroupLayout.PREFERRED_SIZE))
70                                                 .addGroup(gl_contentPane.createSequentialGroup()
71                                                         .addGap(85)
72                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
73                                                                 .addComponent(btnDelete)
74                                                                 .addComponent(rdbtnIAmSure))))
75                                         .addContainerGap(954, Short.MAX_VALUE))
76                 );
77                 gl_contentPane.setVerticalGroup(
78                         gl_contentPane.createParallelGroup(Alignment.LEADING)
79                                 .addGroup(gl_contentPane.createSequentialGroup()
80                                         .addGap(50)
81                                         .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
82                                         .addGap(68)
83                                         .addComponent(rdbtnIAmSure)
84                                         .addGap(47)
85                                         .addComponent(btnDelete)
86                                         .addContainerGap(493, Short.MAX_VALUE))
87                 );
88                 contentPane.setLayout(gl_contentPane);
89                 
90                 btnDelete.addActionListener(new ActionListener() {
91                         public void actionPerformed(ActionEvent arg0) {
92                                 actionListenerButton(arg0);
93                                 
94                         }
95
96                         
97                 });
98         }
99         
100         private void actionListenerButton(ActionEvent e){
101                 RuralHouse toDel = (RuralHouse)comboBox.getSelectedItem();
102                 
103                 am.addDeletionRequest(toDel);
104         }
105 }