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