implemented lacking GUIs and corrected errors
[RRRRHHHH_Code] / ruralHouses / src / gui / StartWindow.java
1 package gui;
2
3 import javax.swing.*;
4
5 import java.awt.*;
6 import java.awt.event.WindowAdapter;
7 import java.awt.event.WindowEvent;
8
9 import businessLogic.FacadeImplementation;
10 import businessLogic.ApplicationFacadeInterface;
11
12 import java.rmi.*;
13
14 import configuration.Config;
15
16 public class StartWindow extends JFrame {
17         
18         public static boolean clientServer = false;
19
20         private static final long serialVersionUID = 1L;
21
22         private JPanel jContentPane = null;
23         private JButton bookHouseButton = null;
24         private JButton createOfferButton = null;
25         private JButton searchAvailabilityButton = null;
26         private JButton exitButton = null;
27
28         public static ApplicationFacadeInterface facadeInterface;
29         
30         public StartWindow() {
31                 super();
32                 initialize();
33                 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
34         }
35         
36         public static ApplicationFacadeInterface getBusinessLogic(){
37                 return facadeInterface;
38         }
39         
40         private void initialize() {
41                 // this.setSize(271, 295);
42                 this.setSize(350, 400);
43                 this.setContentPane(getJContentPane());
44                 this.setTitle("Rural Houses");
45         }
46
47         private JPanel getJContentPane() {
48                 if (jContentPane == null) {
49                         jContentPane = new JPanel();
50 //                      jContentPane.setLayout(null);
51                         jContentPane.setLayout(new BoxLayout(jContentPane,
52                                         BoxLayout.Y_AXIS));
53                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
54                         jContentPane.add(getBookHouseButton());
55                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
56                         jContentPane.add(getSearchAvailabilityButton());
57                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
58                         jContentPane.add(getCreateOfferButton());
59                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
60                         jContentPane.add(getExitButton());
61                         jContentPane.add(Box.createRigidArea(new Dimension(0,40)));
62                 }
63                 return jContentPane;
64         }
65
66         private JButton getBookHouseButton() {
67                 if (bookHouseButton == null) {
68                         bookHouseButton = new JButton();
69                         bookHouseButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
70                         bookHouseButton.setText("Book rural house");
71                         bookHouseButton.setAlignmentX(Component.CENTER_ALIGNMENT);
72                         bookHouseButton.addActionListener(new java.awt.event.ActionListener() {
73                                 public void actionPerformed(java.awt.event.ActionEvent e) {
74                                         JFrame a = new BookRuralHouseGUI();
75                                         a.setVisible(true);
76                                 }
77                         });
78                 }
79                 return bookHouseButton;
80         }
81
82         private JButton getCreateOfferButton() {
83                 if (createOfferButton == null) {
84                         createOfferButton = new JButton();
85                         createOfferButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
86                         createOfferButton.setText("Introduce new offer");
87                         createOfferButton.setAlignmentX(Component.CENTER_ALIGNMENT);
88                         createOfferButton.addActionListener(new java.awt.event.ActionListener() {
89                                 public void actionPerformed(java.awt.event.ActionEvent e) {
90                                         JFrame a = new LoginGUI();
91                                         a.setVisible(true);
92                                 }
93                         });
94                 }
95                 return createOfferButton;
96         }
97         
98         private JButton getSearchAvailabilityButton() {
99                 if (searchAvailabilityButton == null) {
100                         searchAvailabilityButton = new JButton();
101                         searchAvailabilityButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
102                         searchAvailabilityButton.setText("Search availability");
103                         searchAvailabilityButton.setAlignmentX(Component.CENTER_ALIGNMENT);
104                         searchAvailabilityButton.addActionListener(new java.awt.event.ActionListener() {
105                                 public void actionPerformed(java.awt.event.ActionEvent e) {
106                                         JFrame a = new SearchOffersGUI();
107                                         a.setVisible(true);
108                                 }
109                         });
110                 }
111                 return searchAvailabilityButton;
112         }
113
114         private JButton getExitButton() {
115                 if (exitButton == null) {
116                         exitButton = new JButton();
117                         exitButton.setText("Exit");
118                         exitButton.setFont(new Font("Tahoma", Font.PLAIN, 24));
119                         exitButton.setAlignmentX(Component.CENTER_ALIGNMENT);
120                         exitButton.addActionListener(new java.awt.event.ActionListener() {
121                                 public void actionPerformed(java.awt.event.ActionEvent e) {
122                                         //JFrame a = new QueryAvailabilityWindow();
123                                         ApplicationFacadeInterface facade=StartWindow.facadeInterface;
124                                         try {
125                                                 
126                                                 setVisible(false);
127                                                 System.exit(1);
128                                         }
129                                         catch (Exception e1) {
130                                                 // TODO Auto-generated catch block
131                                                 e1.printStackTrace();
132                                         }                                       
133                                 }
134                         });
135                 }
136                 return exitButton;
137         }
138         
139         public static void main(String[] args) {                
140                 try {
141                         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
142
143                         Config c=Config.getInstance();
144                         if (!clientServer)
145                                 facadeInterface=new FacadeImplementation();
146                         else {
147                                 final String serverRMI = c.getServerRMI();
148                                 // Remote service name
149                                 String serviceName = "/"+c.getServiceRMI();
150                                 //System.setSecurityManager(new RMISecurityManager());
151                                 // RMI server port number
152                                 int portNumber = Integer.parseInt(c.getPortRMI());
153                                 // RMI server host IP IP 
154                                 facadeInterface = (ApplicationFacadeInterface) Naming.lookup("rmi://"
155                                         + serverRMI + ":" + portNumber + serviceName);
156                         } 
157
158                 }
159                 catch (Exception e) {
160                         //System.out.println(e.toString());
161                         e.printStackTrace();
162                 }
163                 JFrame a = new StartWindow();
164                 a.setVisible(true);
165         }
166
167 } //@jve:decl-index=0:visual-constraint="0,0"