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 import java.util.Vector;
9 import javax.swing.GroupLayout;
10 import javax.swing.GroupLayout.Alignment;
11 import javax.swing.JButton;
12 import javax.swing.JComboBox;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JRadioButton;
17 import javax.swing.border.EmptyBorder;
19 import businessLogic.OfferManager;
22 import domain.RuralHouse;
24 public class DeleteOfferGUI extends JFrame {
29 private static final long serialVersionUID = 1L;
30 private JPanel contentPane;
32 private JComboBox<RuralHouse> comboBox;
33 private JComboBox<Offer> comboBox_1;
34 private JButton btnDelete;
40 public DeleteOfferGUI(Owner o) {
42 setBounds(100, 100, 450, 300);
43 contentPane = new JPanel();
44 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
45 setContentPane(contentPane);
47 comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses());
51 comboBox_1 = new JComboBox<Offer>();
53 JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
55 btnDelete = new JButton("DELETE");
56 btnDelete.setEnabled(false);
58 comboBox.addItemListener(new ItemListener() {
61 public void itemStateChanged(ItemEvent arg0) {
62 Vector<Offer> vo = ((RuralHouse)comboBox.getSelectedItem()).offers;
63 comboBox_1.removeAllItems();
65 comboBox_1.addItem(of);;
72 rdbtnIAmSure.addItemListener(new ItemListener() {
75 public void itemStateChanged(ItemEvent e) {
76 int state = e.getStateChange();
77 if (state == ItemEvent.SELECTED){
78 btnDelete.setEnabled(true);
80 else if (state == ItemEvent.DESELECTED){
81 btnDelete.setEnabled(false);
86 JLabel lblHouse = new JLabel("House:");
88 JLabel lblOffer = new JLabel("Offer:");
89 GroupLayout gl_contentPane = new GroupLayout(contentPane);
90 gl_contentPane.setHorizontalGroup(
91 gl_contentPane.createParallelGroup(Alignment.LEADING)
92 .addGroup(gl_contentPane.createSequentialGroup()
93 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
94 .addGroup(gl_contentPane.createSequentialGroup()
96 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
97 .addComponent(btnDelete)
98 .addComponent(rdbtnIAmSure)))
99 .addGroup(gl_contentPane.createSequentialGroup()
101 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
102 .addComponent(lblHouse, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
103 .addComponent(lblOffer, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE))
105 .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
106 .addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
107 .addComponent(comboBox_1, 0, 314, Short.MAX_VALUE))))
108 .addContainerGap(946, Short.MAX_VALUE))
110 gl_contentPane.setVerticalGroup(
111 gl_contentPane.createParallelGroup(Alignment.LEADING)
112 .addGroup(gl_contentPane.createSequentialGroup()
114 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
115 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
116 .addComponent(lblHouse))
118 .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
119 .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
120 .addComponent(lblOffer))
122 .addComponent(rdbtnIAmSure)
124 .addComponent(btnDelete)
125 .addContainerGap(493, Short.MAX_VALUE))
127 contentPane.setLayout(gl_contentPane);
129 btnDelete.addActionListener(new ActionListener() {
130 public void actionPerformed(ActionEvent arg0) {
131 actionListenerButton(arg0);
139 private void actionListenerButton(ActionEvent e){
141 Offer toDel = (Offer)comboBox_1.getSelectedItem();
142 OfferManager oM = new OfferManager();
144 oM.deleteOffer((RuralHouse)comboBox.getSelectedItem(),toDel);
145 } catch (Exception e1) {
146 e1.printStackTrace();
148 comboBox.removeItem(toDel);