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