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;
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;
21 import businessLogic.HouseManager;
22 import businessLogic.HouseManagerInterface;
23 import businessLogic.OfferManager;
26 import domain.RuralHouse;
28 import javax.swing.JLabel;
29 import javax.swing.LayoutStyle.ComponentPlacement;
31 public class DeleteOfferGUI extends JFrame {
36 private static final long serialVersionUID = 1L;
37 private JPanel contentPane;
39 private JComboBox<RuralHouse> comboBox;
40 private JComboBox<Offer> comboBox_1;
41 private JButton btnDelete;
47 public DeleteOfferGUI(Owner o) {
49 setBounds(100, 100, 450, 300);
50 contentPane = new JPanel();
51 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
52 setContentPane(contentPane);
54 comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses());
58 comboBox_1 = new JComboBox<Offer>();
60 JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
62 btnDelete = new JButton("DELETE");
63 btnDelete.setEnabled(false);
65 comboBox.addItemListener(new ItemListener() {
68 public void itemStateChanged(ItemEvent arg0) {
69 Vector<Offer> vo = ((RuralHouse)comboBox.getSelectedItem()).offers;
70 comboBox_1.removeAllItems();
72 comboBox_1.addItem(of);;
79 rdbtnIAmSure.addItemListener(new ItemListener() {
82 public void itemStateChanged(ItemEvent e) {
83 int state = e.getStateChange();
84 if (state == ItemEvent.SELECTED){
85 btnDelete.setEnabled(true);
87 else if (state == ItemEvent.DESELECTED){
88 btnDelete.setEnabled(false);
93 JLabel lblHouse = new JLabel("House:");
95 JLabel lblOffer = new JLabel("Offer:");
96 GroupLayout gl_contentPane = new GroupLayout(contentPane);
97 gl_contentPane.setHorizontalGroup(
98 gl_contentPane.createParallelGroup(Alignment.LEADING)
99 .addGroup(gl_contentPane.createSequentialGroup()
100 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
101 .addGroup(gl_contentPane.createSequentialGroup()
103 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
104 .addComponent(btnDelete)
105 .addComponent(rdbtnIAmSure)))
106 .addGroup(gl_contentPane.createSequentialGroup()
108 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
109 .addComponent(lblHouse, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
110 .addComponent(lblOffer, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE))
112 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
113 .addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
114 .addComponent(comboBox_1, 0, 314, Short.MAX_VALUE))))
115 .addContainerGap(946, Short.MAX_VALUE))
117 gl_contentPane.setVerticalGroup(
118 gl_contentPane.createParallelGroup(Alignment.LEADING)
119 .addGroup(gl_contentPane.createSequentialGroup()
121 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
122 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
123 .addComponent(lblHouse))
125 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
126 .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
127 .addComponent(lblOffer))
129 .addComponent(rdbtnIAmSure)
131 .addComponent(btnDelete)
132 .addContainerGap(493, Short.MAX_VALUE))
134 contentPane.setLayout(gl_contentPane);
136 btnDelete.addActionListener(new ActionListener() {
137 public void actionPerformed(ActionEvent arg0) {
138 actionListenerButton(arg0);
146 private void actionListenerButton(ActionEvent e){
148 Offer toDel = (Offer)comboBox_1.getSelectedItem();
149 OfferManager oM = new OfferManager();
151 oM.deleteOffer((RuralHouse)comboBox.getSelectedItem(),toDel);
152 } catch (Exception e1) {
153 e1.printStackTrace();
155 comboBox.removeItem(toDel);