deleted: ruralHouses/hs_err_pid6014.log
[RRRRHHHH_Code] / ruralHouses / src / gui / DeleteOfferGUI.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.rmi.RemoteException;
10 import java.util.Vector;
11
12 import javax.swing.JFrame;
13 import javax.swing.JPanel;
14 import javax.swing.border.EmptyBorder;
15 import javax.swing.GroupLayout;
16 import javax.swing.GroupLayout.Alignment;
17 import javax.swing.JComboBox;
18 import javax.swing.JRadioButton;
19 import javax.swing.JButton;
20
21 import businessLogic.HouseManager;
22 import businessLogic.HouseManagerInterface;
23 import businessLogic.OfferManager;
24 import domain.Offer;
25 import domain.Owner;
26 import domain.RuralHouse;
27 import javax.swing.JLabel;
28 import javax.swing.LayoutStyle.ComponentPlacement;
29
30 public class DeleteOfferGUI extends JFrame {
31
32         private JPanel contentPane;
33         private Owner owner;
34         private JComboBox comboBox;
35         private JComboBox comboBox_1;
36         private JButton btnDelete;
37
38
39         /**
40          * Create the frame.
41          */
42         public DeleteOfferGUI(Owner o) {
43                 this.owner = o;
44                 setBounds(100, 100, 450, 300);
45                 contentPane = new JPanel();
46                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
47                 setContentPane(contentPane);
48         
49                 comboBox = new JComboBox(this.owner.getRuralHouses());
50                 
51                 
52                 
53                 comboBox_1 = new JComboBox(((RuralHouse)comboBox.getSelectedItem()).offers);
54
55                 JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
56                 
57                 btnDelete = new JButton("DELETE");
58                 btnDelete.setEnabled(false);
59                 
60                 rdbtnIAmSure.addItemListener(new ItemListener() {
61
62                         @Override
63                         public void itemStateChanged(ItemEvent e) {
64                                 int state = e.getStateChange();
65                                 if (state == ItemEvent.SELECTED){
66                                         btnDelete.setEnabled(true);
67                                 }
68                                 else if (state == ItemEvent.DESELECTED){
69                                         btnDelete.setEnabled(false);
70                                 }
71                         }
72                 });
73                 
74                 JLabel lblHouse = new JLabel("House:");
75                 
76                 JLabel lblOffer = new JLabel("Offer:");
77                 GroupLayout gl_contentPane = new GroupLayout(contentPane);
78                 gl_contentPane.setHorizontalGroup(
79                         gl_contentPane.createParallelGroup(Alignment.LEADING)
80                                 .addGroup(gl_contentPane.createSequentialGroup()
81                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
82                                                 .addGroup(gl_contentPane.createSequentialGroup()
83                                                         .addGap(85)
84                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
85                                                                 .addComponent(btnDelete)
86                                                                 .addComponent(rdbtnIAmSure)))
87                                                 .addGroup(gl_contentPane.createSequentialGroup()
88                                                         .addGap(20)
89                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
90                                                                 .addComponent(lblHouse, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
91                                                                 .addComponent(lblOffer, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE))
92                                                         .addGap(8)
93                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
94                                                                 .addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
95                                                                 .addComponent(comboBox_1, 0, 314, Short.MAX_VALUE))))
96                                         .addContainerGap(946, Short.MAX_VALUE))
97                 );
98                 gl_contentPane.setVerticalGroup(
99                         gl_contentPane.createParallelGroup(Alignment.LEADING)
100                                 .addGroup(gl_contentPane.createSequentialGroup()
101                                         .addGap(33)
102                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
103                                                 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
104                                                 .addComponent(lblHouse))
105                                         .addGap(18)
106                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
107                                                 .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
108                                                 .addComponent(lblOffer))
109                                         .addGap(43)
110                                         .addComponent(rdbtnIAmSure)
111                                         .addGap(47)
112                                         .addComponent(btnDelete)
113                                         .addContainerGap(493, Short.MAX_VALUE))
114                 );
115                 contentPane.setLayout(gl_contentPane);
116                 
117                 btnDelete.addActionListener(new ActionListener() {
118                         public void actionPerformed(ActionEvent arg0) {
119                                 actionListenerButton(arg0);
120                                 
121                         }
122
123                         
124                 });
125         }
126         
127         private void actionListenerButton(ActionEvent e){
128
129                 Offer toDel = (Offer)comboBox_1.getSelectedItem();
130                 OfferManager oM = new OfferManager();
131                 try {
132                         oM.deleteOffer((RuralHouse)comboBox.getSelectedItem(),toDel);
133                 } catch (Exception e1) {
134                         e1.printStackTrace();
135                 }
136                 comboBox.removeItem(toDel);
137         }
138 }