package gui; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.Vector; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.border.EmptyBorder; import businessLogic.OfferManager; import domain.Offer; import domain.Owner; import domain.RuralHouse; public class DeleteOfferGUI extends JFrame { /** * */ private static final long serialVersionUID = 1L; private JPanel contentPane; private Owner owner; private JComboBox comboBox; private JComboBox comboBox_1; private JButton btnDelete; /** * Create the frame. */ public DeleteOfferGUI(Owner o) { this.owner = o; setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); comboBox = new JComboBox(this.owner.getRuralHouses()); comboBox_1 = new JComboBox(); JRadioButton rdbtnIAmSure = new JRadioButton("I am sure"); btnDelete = new JButton("DELETE"); btnDelete.setEnabled(false); comboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent arg0) { Vector vo = ((RuralHouse)comboBox.getSelectedItem()).offers; comboBox_1.removeAllItems(); for (Offer of: vo){ comboBox_1.addItem(of);; } } }); rdbtnIAmSure.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { int state = e.getStateChange(); if (state == ItemEvent.SELECTED){ btnDelete.setEnabled(true); } else if (state == ItemEvent.DESELECTED){ btnDelete.setEnabled(false); } } }); JLabel lblHouse = new JLabel("House:"); JLabel lblOffer = new JLabel("Offer:"); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup( gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGap(85) .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) .addComponent(btnDelete) .addComponent(rdbtnIAmSure))) .addGroup(gl_contentPane.createSequentialGroup() .addGap(20) .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false) .addComponent(lblHouse, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(lblOffer, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)) .addGap(8) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false) .addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(comboBox_1, 0, 314, Short.MAX_VALUE)))) .addContainerGap(946, Short.MAX_VALUE)) ); gl_contentPane.setVerticalGroup( gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGap(33) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblHouse)) .addGap(18) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblOffer)) .addGap(43) .addComponent(rdbtnIAmSure) .addGap(47) .addComponent(btnDelete) .addContainerGap(493, Short.MAX_VALUE)) ); contentPane.setLayout(gl_contentPane); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionListenerButton(arg0); } }); } private void actionListenerButton(ActionEvent e){ Offer toDel = (Offer)comboBox_1.getSelectedItem(); OfferManager oM = new OfferManager(); try { oM.deleteOffer((RuralHouse)comboBox.getSelectedItem(),toDel); } catch (Exception e1) { e1.printStackTrace(); } comboBox.removeItem(toDel); } }