Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code
[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.KeyEventDispatcher;
9 import java.awt.KeyboardFocusManager;
10 import java.awt.event.KeyEvent;
11 import java.awt.event.WindowAdapter;
12 import java.awt.event.WindowEvent;
13 import java.rmi.RMISecurityManager;
14
15 import javax.swing.JButton;
16 import javax.swing.JFrame;
17 import javax.swing.JLabel;
18 import javax.swing.JPanel;
19 import javax.swing.SwingConstants;
20 import javax.swing.UIManager;
21
22 import configuration.ConfigXML;
23
24 @SuppressWarnings("deprecation")
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         private JLabel lblNewLabel;
34
35         public static void main(String[] args) {
36
37                 StartWindow a = new StartWindow();
38                 
39                 System.setProperty("java.security.policy", "java.policy");
40                 
41                 a.setVisible(true);
42
43                 try {
44
45                         c = ConfigXML.getInstance();
46
47                         System.setProperty("java.security.policy", c.getJavaPolicyPath());
48
49                         System.setSecurityManager(new RMISecurityManager());
50
51                         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
52
53                         c = configuration.ConfigXML.getInstance();
54
55                 } catch (com.db4o.ext.DatabaseFileLockedException e) {
56                         a.lblNewLabel
57                                         .setText("Database locked: Do not run BusinessLogicServer or BusinessLogicServer!!");
58                         a.lblNewLabel.setForeground(Color.RED);
59                         System.out.println("Error in StartWindow: " + e.toString());
60                 } catch (Exception e) {
61                         a.lblNewLabel.setText("Error: " + e.toString());
62                         a.lblNewLabel.setForeground(Color.RED);
63                         System.out.println("Error in StartWindow: " + e.toString());
64                 }
65
66         }
67
68         /**
69          * This is the default constructor
70          */
71
72         public StartWindow() {
73                 super();
74
75                 addWindowListener(new WindowAdapter() {
76                         @Override
77                         public void windowClosing(WindowEvent e) {
78
79                                 System.exit(1);
80                         }
81
82                 });
83
84                 KeyboardFocusManager.getCurrentKeyboardFocusManager()
85                                 .addKeyEventDispatcher(new KeyEventDispatcher() {
86
87                                         @Override
88                                         public boolean dispatchKeyEvent(KeyEvent e) {
89                                                 switch (e.getKeyCode()) {
90
91                                                 case KeyEvent.VK_ESCAPE:
92                                                         System.exit(1);
93                                                 
94                                                 }
95                                                 return false;
96                                         }
97                                 });
98                 initialize();
99                 // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
100         }
101
102         /**
103          * This method initializes this
104          * 
105          * @return void
106          */
107         private void initialize() {
108                 // this.setSize(271, 295);
109                 this.setSize(495, 290);
110                 this.setContentPane(getJContentPane());
111                 this.setTitle("Rural Houses");
112         }
113
114         /**
115          * This method initializes jContentPane
116          * 
117          * @return javax.swing.JPanel
118          */
119         private JPanel getJContentPane() {
120                 if (jContentPane == null) {
121                         jContentPane = new JPanel();
122                         jContentPane.setLayout(null);
123                         jContentPane.add(getLblNewLabel());
124                         jContentPane.add(getBoton2());
125                         jContentPane.add(getBoton3());
126                 }
127                 return jContentPane;
128         }
129
130         /**
131          * This method initializes boton2
132          * 
133          * @return javax.swing.JButton
134          */
135         private JButton getBoton2() {
136                 if (boton2 == null) {
137                         boton2 = new JButton();
138                         boton2.setBounds(0, 74, 479, 93);
139                         boton2.setText("Login");
140                         boton2.addActionListener(new java.awt.event.ActionListener() {
141                                 public void actionPerformed(java.awt.event.ActionEvent e) {
142                                         // C?digo cedido por la universidad
143                                         JFrame a = new LoginGUI();
144                                         a.setVisible(true);
145                                 }
146                         });
147                 }
148                 return boton2;
149         }
150
151         /**
152          * This method initializes boton3
153          * 
154          * @return javax.swing.JButton
155          */
156         private JButton getBoton3() {
157                 if (boton3 == null) {
158                         boton3 = new JButton();
159                         boton3.setBounds(0, 165, 479, 87);
160                         boton3.setText("Query availability");
161                         boton3.addActionListener(new java.awt.event.ActionListener() {
162                                 public void actionPerformed(java.awt.event.ActionEvent e) {
163                                         // C?digo cedido por la universidad
164                                         // JFrame a = new QueryAvailabilityWindow();
165                                         JFrame a = new QueryAvailabilityGUI2();
166
167                                         a.setVisible(true);
168                                 }
169                         });
170                 }
171                 return boton3;
172         }
173
174         private JLabel getLblNewLabel() {
175                 if (lblNewLabel == null) {
176                         lblNewLabel = new JLabel("Select option:");
177                         lblNewLabel.setBounds(0, 0, 479, 63);
178                         lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 13));
179                         lblNewLabel.setForeground(Color.BLACK);
180                         lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
181                 }
182                 return lblNewLabel;
183         }
184
185 } // @jve:decl-index=0:visual-constraint="0,0"
186