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