VersiĆ³n del proyecto de Apuestas tras la iteraciĆ³n 1
[ISBets21MAUBRY] / eclipse-workspace / ISBets21BRYMAUJONUNA / src / main / java / gui / MainGUI.java
1 package gui;
2
3 import java.awt.Color;
4 import java.awt.EventQueue;
5 import java.awt.Font;
6 import java.awt.GridLayout;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.awt.event.WindowAdapter;
10 import java.awt.event.WindowEvent;
11 import java.util.Locale;
12 import java.util.ResourceBundle;
13 import java.util.Vector;
14
15 /**
16  * @author Software Engineering teachers
17  */
18 import javax.swing.ButtonGroup;
19 import javax.swing.JButton;
20 import javax.swing.JFrame;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JRadioButton;
24 import javax.swing.SwingConstants;
25
26 import businessLogic.BLFacade;
27 import businessLogic.BLFacadeImplementation;
28 import domain.Event;
29
30 public class MainGUI extends JFrame {
31
32         private static final long serialVersionUID = 1L;
33
34         private JPanel jContentPane = null;
35         private JButton jButtonCreateQuery = null;
36         private JButton jButtonQueryQueries = null;
37
38         private static BLFacade appFacadeInterface = LoginGUI.getBusinessLogic();
39
40
41         protected JLabel jLabelSelectOption;
42         private JRadioButton rdbtnNewRadioButton;
43         private JRadioButton rdbtnNewRadioButton_1;
44         private JRadioButton rdbtnNewRadioButton_2;
45         private JPanel panel;
46         private final ButtonGroup buttonGroup = new ButtonGroup();
47
48         /**
49          * This is the default constructor
50          */
51         public MainGUI() {
52                 super();
53
54                 addWindowListener(new WindowAdapter() {
55                         @Override
56                         public void windowClosing(WindowEvent e) {
57                                 try {
58                                         // if (ConfigXML.getInstance().isBusinessLogicLocal()) facade.close();
59                                 } catch (Exception e1) {
60                                         // TODO Auto-generated catch block
61                                         System.out.println(
62                                                         "Error: " + e1.toString() + " , probably problems with Business Logic or Database");
63                                 }
64                                 System.exit(1);
65                         }
66                 });
67
68                 initialize();
69                 // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70         }
71
72         /**
73          * This method initializes this
74          * 
75          * @return void
76          */
77         private void initialize() {
78                 // this.setSize(271, 295);
79                 this.setSize(550, 363);
80                 this.setContentPane(getJContentPane());
81                 this.setTitle(ResourceBundle.getBundle("Etiquetas").getString("MainTitle"));
82         }
83
84         /**
85          * This method initializes jContentPane
86          * 
87          * @return javax.swing.JPanel
88          */
89         private JPanel getJContentPane() {
90                 if (jContentPane == null) {
91                         jContentPane = new JPanel();
92                         jContentPane.setLayout(new GridLayout(4, 1, 0, 0));
93                         jContentPane.add(getLblNewLabel());
94                         jContentPane.add(getBoton3());
95                         jContentPane.add(getBoton2());
96                         jContentPane.add(getPanel());
97                 }
98                 return jContentPane;
99         }
100
101         /**
102          * This method initializes boton1
103          * 
104          * @return javax.swing.JButton
105          */
106         private JButton getBoton2() {
107                 if (jButtonCreateQuery == null) {
108                         jButtonCreateQuery = new JButton();
109                         jButtonCreateQuery.setText(ResourceBundle.getBundle("Etiquetas").getString("CreateQuery"));
110                         jButtonCreateQuery.addActionListener(new java.awt.event.ActionListener() {
111                                 public void actionPerformed(java.awt.event.ActionEvent e) {
112                                         JFrame a = new CreateQuestionGUI(new Vector<Event>());
113                                         a.setAlwaysOnTop(true);
114                                         a.setVisible(true);
115                                 }
116                         });
117                 }
118                 return jButtonCreateQuery;
119         }
120
121         /**
122          * This method initializes boton2
123          * 
124          * @return javax.swing.JButton
125          */
126         private JButton getBoton3() {
127                 if (jButtonQueryQueries == null) {
128                         jButtonQueryQueries = new JButton();
129                         jButtonQueryQueries.setText(ResourceBundle.getBundle("Etiquetas").getString("QueryQueries"));
130                         jButtonQueryQueries.addActionListener(new java.awt.event.ActionListener() {
131                                 public void actionPerformed(java.awt.event.ActionEvent e) {
132                                         JFrame a = new FindQuestionsGUI();
133                                         a.setAlwaysOnTop(true);
134                                         a.setVisible(true);
135                                         a.setVisible(true);
136                                 }
137                         });
138                 }
139                 return jButtonQueryQueries;
140         }
141
142         private JLabel getLblNewLabel() {
143                 if (jLabelSelectOption == null) {
144                         jLabelSelectOption = new JLabel(ResourceBundle.getBundle("Etiquetas").getString("SelectOption"));
145                         jLabelSelectOption.setFont(new Font("Tahoma", Font.BOLD, 13));
146                         jLabelSelectOption.setForeground(Color.BLACK);
147                         jLabelSelectOption.setHorizontalAlignment(SwingConstants.CENTER);
148                 }
149                 return jLabelSelectOption;
150         }
151
152         private JRadioButton getRdbtnNewRadioButton() {
153                 if (rdbtnNewRadioButton == null) {
154                         rdbtnNewRadioButton = new JRadioButton("English");
155                         rdbtnNewRadioButton.addActionListener(new ActionListener() {
156                                 public void actionPerformed(ActionEvent e) {
157                                         Locale.setDefault(new Locale("en"));
158                                         System.out.println("Locale: " + Locale.getDefault());
159                                         redibujar();
160                                 }
161                         });
162                         buttonGroup.add(rdbtnNewRadioButton);
163                 }
164                 return rdbtnNewRadioButton;
165         }
166
167         private JRadioButton getRdbtnNewRadioButton_1() {
168                 if (rdbtnNewRadioButton_1 == null) {
169                         rdbtnNewRadioButton_1 = new JRadioButton("Euskara");
170                         rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
171                                 public void actionPerformed(ActionEvent arg0) {
172                                         Locale.setDefault(new Locale("eus"));
173                                         System.out.println("Locale: " + Locale.getDefault());
174                                         redibujar();
175                                 }
176                         });
177                         buttonGroup.add(rdbtnNewRadioButton_1);
178                 }
179                 return rdbtnNewRadioButton_1;
180         }
181
182         private JRadioButton getRdbtnNewRadioButton_2() {
183                 if (rdbtnNewRadioButton_2 == null) {
184                         rdbtnNewRadioButton_2 = new JRadioButton("Castellano");
185                         rdbtnNewRadioButton_2.addActionListener(new ActionListener() {
186                                 public void actionPerformed(ActionEvent e) {
187                                         Locale.setDefault(new Locale("es"));
188                                         System.out.println("Locale: " + Locale.getDefault());
189                                         redibujar();
190                                 }
191                         });
192                         buttonGroup.add(rdbtnNewRadioButton_2);
193                 }
194                 return rdbtnNewRadioButton_2;
195         }
196
197         private JPanel getPanel() {
198                 if (panel == null) {
199                         panel = new JPanel();
200                         panel.add(getRdbtnNewRadioButton_1());
201                         panel.add(getRdbtnNewRadioButton_2());
202                         panel.add(getRdbtnNewRadioButton());
203                 }
204                 return panel;
205         }
206
207
208         private void redibujar() {
209                 jLabelSelectOption.setText(ResourceBundle.getBundle("Etiquetas").getString("SelectOption"));
210                 jButtonQueryQueries.setText(ResourceBundle.getBundle("Etiquetas").getString("QueryQueries"));
211                 jButtonCreateQuery.setText(ResourceBundle.getBundle("Etiquetas").getString("CreateQuery"));
212                 this.setTitle(ResourceBundle.getBundle("Etiquetas").getString("MainTitle"));
213         }
214         
215         public void close() {
216                 this.setVisible(false);
217         }
218
219 } // @jve:decl-index=0:visual-constraint="0,0"