GUI added to show list of available houses
[RRRRHHHH_Code] / ruralHouses / src / gui / StartWindow.java
1 package gui;
2
3 /**
4  * @author willCodeForFood
5  */
6 import exceptions.DB4oManagerCreationException;
7 import gui.BookRuralHouseGUI;
8
9 import javax.swing.*;
10
11 import configuration.ConfigXML;
12 import java.rmi.*;
13 import java.awt.Color;
14 import java.awt.Font;
15 import java.awt.Rectangle;
16 import java.awt.Dimension;
17 import java.awt.BorderLayout;
18 import java.awt.FlowLayout;
19 import java.awt.GridLayout;
20 import java.awt.GridBagLayout;
21 import java.awt.GridBagConstraints;
22 import java.awt.event.WindowAdapter;
23 import java.awt.event.WindowEvent;
24
25
26 public class StartWindow extends JFrame {
27         
28         private static final long serialVersionUID = 1L;
29
30         private JPanel jContentPane = null;
31         private JButton boton1 = null;
32         private JButton boton2 = null;
33         private JButton boton3 = null;
34         private static configuration.ConfigXML c;
35
36         //public static ApplicationFacadeInterface facadeInterface;
37         private JLabel lblNewLabel;
38         
39         public static void main(String[] args) {
40
41                 StartWindow a = new StartWindow();
42                 a.setVisible(true);
43                 
44                 try {
45
46                         c=ConfigXML.getInstance();
47
48                         System.setProperty("java.security.policy", c.getJavaPolicyPath());
49                                                 
50                         System.setSecurityManager(new RMISecurityManager());
51
52                         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
53
54                         c=configuration.ConfigXML.getInstance();
55                         if (c.isBusinessLogicLocal()){
56                                 //facadeInterface=new FacadeImplementation();
57                         }
58                         else {
59                                 
60                                 final String businessLogicNode = c.getBusinessLogicNode();
61                                 // Remote service name
62                                 String serviceName = "/"+c.getServiceRMI();
63                                 // RMI server port number
64                                 int portNumber = Integer.parseInt(c.getPortRMI());
65                                 // RMI server host IP IP 
66                                 /*facadeInterface = (ApplicationFacadeInterface) Naming.lookup("rmi://"
67                                         + businessLogicNode + ":" + portNumber + serviceName);*/
68                         } 
69
70                 }/* catch (java.rmi.ConnectException e) {
71                         a.lblNewLabel.setText("No business logic: Run BusinessLogicServer first!!");
72                         a.lblNewLabel.setForeground(Color.RED);
73                         System.out.println("Error in StartWindow: "+e.toString());
74                 } catch (java.rmi.NotBoundException e) {
75                         a.lblNewLabel.setText("No business logic: Maybe problems running BusinessLogicServer");
76                         a.lblNewLabel.setForeground(Color.RED);
77                         System.out.println("Error in StartWindow: "+e.toString());
78                 } */catch (com.db4o.ext.DatabaseFileLockedException e) {
79                         a.lblNewLabel.setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!");
80                         a.lblNewLabel.setForeground(Color.RED);         
81                         System.out.println("Error in StartWindow: "+e.toString());
82                 } catch (Exception e) {
83                         a.lblNewLabel.setText("Error: "+e.toString());
84                         a.lblNewLabel.setForeground(Color.RED);         
85                         System.out.println("Error in StartWindow: "+e.toString());
86                 }
87                 //a.pack();
88
89                 
90
91         }
92         /**
93          * This is the default constructor
94          */
95
96         public StartWindow() {
97                 super();
98
99                 addWindowListener(new WindowAdapter() {
100                         @Override
101                         public void windowClosing(WindowEvent e) {
102                                 System.exit(1);
103                         }
104                 });
105                 initialize();
106                 //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
107         }
108         
109         
110
111         /**
112          * This method initializes this
113          * 
114          * @return void
115          */
116         private void initialize() {
117                 // this.setSize(271, 295);
118                 this.setSize(495, 290);
119                 this.setContentPane(getJContentPane());
120                 this.setTitle("Rural Houses");
121         }
122
123         /**
124          * This method initializes jContentPane
125          * 
126          * @return javax.swing.JPanel
127          */
128         private JPanel getJContentPane() {
129                 if (jContentPane == null) {
130                         GridLayout gridLayout = new GridLayout();
131                         gridLayout.setRows(4);
132                         gridLayout.setColumns(1);
133                         jContentPane = new JPanel();
134                         jContentPane.setLayout(gridLayout);
135                         jContentPane.add(getLblNewLabel());
136                         jContentPane.add(getBoton2(), null);
137                         jContentPane.add(getBoton3(), null);
138                         jContentPane.add(getBoton1(), null);
139                 }
140                 return jContentPane;
141         }
142
143         /**
144          * This method initializes boton1
145          * 
146          * @return javax.swing.JButton
147          */
148         private JButton getBoton1() {
149                 if (boton1 == null) {
150                         boton1 = new JButton();
151                         boton1.setText("Book rural house");
152                         boton1.addActionListener(new java.awt.event.ActionListener() {
153                                 public void actionPerformed(java.awt.event.ActionEvent e) {
154                                         // C?digo cedido por la univerdad
155                                         JFrame a = new BookRuralHouseGUI();
156                                         a.setVisible(true);
157                                 }
158                         });
159                 }
160                 return boton1;
161         }
162
163         /**
164          * This method initializes boton2
165          * 
166          * @return javax.swing.JButton
167          */
168         private JButton getBoton2() {
169                 if (boton2 == null) {
170                         boton2 = new JButton();
171                         boton2.setText("Login");
172                         boton2.addActionListener(new java.awt.event.ActionListener() {
173                                 public void actionPerformed(java.awt.event.ActionEvent e) {
174                                         // C?digo cedido por la universidad
175                                         JFrame a = new LoginGUI();
176                                         a.setVisible(true);
177                                 }
178                         });
179                 }
180                 return boton2;
181         }
182         
183         /**
184          * This method initializes boton3
185          * 
186          * @return javax.swing.JButton
187          */
188         private JButton getBoton3() {
189                 if (boton3 == null) {
190                         boton3 = new JButton();
191                         boton3.setText("Query availability");
192                         boton3.addActionListener(new java.awt.event.ActionListener() {
193                                 public void actionPerformed(java.awt.event.ActionEvent e) {
194                                         // C?digo cedido por la universidad
195                                         //JFrame a = new QueryAvailabilityWindow();
196                                         JFrame a = new QueryAvailabilityGUI2();
197
198                                         a.setVisible(true);
199                                 }
200                         });
201                 }
202                 return boton3;
203         }
204         
205
206         private JLabel getLblNewLabel() {
207                 if (lblNewLabel == null) {
208                         lblNewLabel = new JLabel("Select option:");
209                         lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 13));
210                         lblNewLabel.setForeground(Color.BLACK);
211                         lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
212                 }
213                 return lblNewLabel;
214         }
215
216 } // @jve:decl-index=0:visual-constraint="0,0"
217