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