Given code uploaded
[RRRRHHHH_Code] / ruralHouses / src / gui / IntroduceOfferGUI.java
1 package gui;
2
3 import javax.swing.*;
4 import java.awt.Rectangle;
5
6 import java.util.Vector;
7
8 import businessLogic.ApplicationFacadeInterface;
9 import domain.Owner;
10 import domain.RuralHouse;
11
12
13 public class IntroduceOfferGUI extends JFrame {
14
15         private static final long serialVersionUID = 1L;
16         private JPanel jContentPane = null;
17         private JComboBox jComboBox = null;
18         private JButton jButton = null;
19
20         public IntroduceOfferGUI() {
21                 super();
22                 initialize();
23         }
24
25         private void initialize() {
26                 this.setSize(449, 293);
27                 this.setContentPane(getJContentPane());
28                 this.setTitle("Choose owner");
29
30         }
31
32         private JPanel getJContentPane() {
33                 if (jContentPane == null) {
34                         jContentPane = new JPanel();
35                         jContentPane.setLayout(null);
36                         jContentPane.add(getJComboBox(), null);
37                         jContentPane.add(getJButton(), null);
38                 }
39                 return jContentPane;
40         }
41
42         private JComboBox getJComboBox() {
43                 if (jComboBox == null) {
44                         try {
45                                 ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
46                                 Vector<Owner> owners=facade.getOwners();
47                                 jComboBox = new JComboBox(owners);
48                                 jComboBox.setBounds(new Rectangle(63, 38, 175, 44));
49                         }
50                         catch (Exception e) {
51                                 // TODO Auto-generated catch block
52                                 e.printStackTrace();
53                         }
54                 }
55                 return jComboBox;
56         }
57
58         private JButton getJButton() {
59                 if (jButton == null) {
60                         jButton = new JButton();
61                         jButton.setBounds(new Rectangle(113, 146, 95, 59));
62                         jButton.setText("Show houses");
63                         jButton.addActionListener(new java.awt.event.ActionListener() {
64                                 public void actionPerformed(java.awt.event.ActionEvent e) {
65                                         Owner owner=(Owner)jComboBox.getSelectedItem();
66                                         System.out.println(owner.getUsername());
67                                         Vector<RuralHouse> houseList=null;
68                                         try {
69                                                 //Obtain the business logic from a StartWindow class (local or remote)
70                                                 ApplicationFacadeInterface facade=StartWindow.getBusinessLogic();
71                                                 houseList=facade.getRuralHouses(owner);
72
73                                         }
74                                         catch (Exception e1) {
75                                                 e1.printStackTrace();
76                                         }
77                                         if (houseList.isEmpty()!=true) {
78                                                 JFrame a = new IntroduceOffer2GUI(houseList);
79                                                 a.setVisible(true);
80                                         }
81                                         else if (houseList.isEmpty()==true) {
82                                                 System.out.print("Owner does not exist or has no registered houses ");
83                                         }               
84                                 }
85                         });
86                 }
87                 return jButton;
88         }
89
90 }  //  @jve:decl-index=0:visual-constraint="222,33"