Iteración 3(Versión sin idiomas)
[ISBets21MAUBRY] / eclipse-workspace / ISBets21MAUBRY / src / main / java / gui / MainGUI.java
1 package gui;
2
3 import java.awt.Color;
4 import java.awt.Font;
5 import java.awt.Frame;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.awt.event.MouseAdapter;
9 import java.awt.event.MouseEvent;
10 import java.awt.event.WindowAdapter;
11 import java.awt.event.WindowEvent;
12 import java.util.Locale;
13
14 /**
15  * @author Software Engineering teachers
16  */
17 import javax.swing.ButtonGroup;
18 import javax.swing.ImageIcon;
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 domain.RegularUser;
28
29 public class MainGUI extends JFrame {
30
31         private static final long serialVersionUID = 1L;
32
33         private JPanel jContentPane = null;
34         private JButton jButtonQueryQueries = null;
35
36         private static BLFacade appFacadeInterface = LoginGUI.getBusinessLogic();
37
38         private RegularUser ru = null;
39         protected JLabel jLabelSelectOption;
40         private JRadioButton rdbtnNewRadioButton;
41         private JRadioButton rdbtnNewRadioButton_1;
42         private JRadioButton rdbtnNewRadioButton_2;
43         private JPanel panel;
44         private final ButtonGroup buttonGroup = new ButtonGroup();
45         private JButton btnModificar = new JButton();
46         private JLabel lblSaldo;
47         private RegularUser userlog = null;
48         private JButton btnBet;
49
50         private JButton btnHistorial;
51         private JButton btnAnularApuesta;
52
53         private JButton btnCargarSaldo = new JButton("Load Balance");
54
55         private JLabel lblFotoPerfil = new JLabel("");
56
57         private JLabel lblFotoCargar = new JLabel("");
58         private JLabel lblFotoMakeBet = new JLabel("");
59         private JLabel lblFotoHistorial = new JLabel("");
60         private JLabel lblFotoAnular = new JLabel("");
61
62         /**
63          * This is the default constructor
64          */
65         public MainGUI(RegularUser ru) {
66                 super();
67
68                 userlog = ru;
69
70                 addWindowListener(new WindowAdapter() {
71                         @Override
72                         public void windowClosing(WindowEvent e) {
73                                 try {
74                                         // if (ConfigXML.getInstance().isBusinessLogicLocal()) facade.close();
75                                 } catch (Exception e1) {
76                                         // TODO Auto-generated catch block
77                                         System.out.println(
78                                                         "Error: " + e1.toString() + " , probably problems with Business Logic or Database");
79                                 }
80                                 // System.exit(1);
81                         }
82                 });
83
84                 initialize();
85                 // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
86         }
87
88         /**
89          * This method initializes this
90          * 
91          * @return void
92          */
93         private void initialize() {
94                 // this.setSize(271, 295);
95                 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
96
97                 this.setSize(820, 650);
98                 this.setContentPane(getJContentPane());
99 //              this.setTitle(ResourceBundle.getBundle("Etiquetas").getString("MainTitle")
100 //                              + "                                                            " + userlog.getUserName());
101                 this.setTitle(
102                                 "MainTitle" + "                                                            " + userlog.getUserName());
103         }
104
105         /**
106          * This method initializes jContentPane
107          * 
108          * @return javax.swing.JPanel
109          */
110         private JPanel getJContentPane() {
111                 if (jContentPane == null) {
112                         jContentPane = new JPanel();
113                         jContentPane.setBackground(Color.WHITE);
114                         jContentPane.setLayout(null);
115
116                         jContentPane.add(getLblNewLabel());
117                         btnModificar.addMouseListener(new MouseAdapter() {
118                                 @Override
119                                 public void mouseEntered(MouseEvent e) {
120                                         lblFotoPerfil.setVisible(true);
121                                 }
122
123                                 @Override
124                                 public void mouseExited(MouseEvent e) {
125                                         lblFotoPerfil.setVisible(false);
126
127                                 }
128                         });
129
130                         btnModificar.setBounds(45, 99, 422, 85);
131                         // jContentPane.add(getBoton3());
132                         jContentPane.add(getBoton2());
133                         jContentPane.add(getBtnBet());
134                         jContentPane.add(getPanel());
135
136                         btnHistorial = new JButton();
137                         btnHistorial.addMouseListener(new MouseAdapter() {
138                                 @Override
139                                 public void mouseEntered(MouseEvent e) {
140                                         lblFotoHistorial.setVisible(true);
141                                 }
142
143                                 @Override
144                                 public void mouseExited(MouseEvent e) {
145                                         lblFotoHistorial.setVisible(false);
146
147                                 }
148                         });
149                         btnHistorial.addActionListener(new ActionListener() {
150                                 @Override
151                                 public void actionPerformed(ActionEvent arg0) {
152
153                                         Frame reg = new HistorialApuestasGUI(userlog);
154                                         reg.setAlwaysOnTop(true);
155                                         reg.setVisible(true);
156                                         dispose();
157
158                                 }
159                         });
160                         // btnHistorial.setText(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.btnHistorial.text"));
161                         // //$NON-NLS-1$ //$NON-NLS-2$
162                         btnHistorial.setText("Check History");
163                         btnHistorial.setBounds(45, 269, 422, 83);
164                         jContentPane.add(btnHistorial);
165                         jContentPane.add(getBtnAnularApuesta());
166                         btnCargarSaldo.addMouseListener(new MouseAdapter() {
167                                 @Override
168                                 public void mouseEntered(MouseEvent arg0) {
169                                         lblFotoCargar.setVisible(true);
170                                 }
171
172                                 @Override
173                                 public void mouseExited(MouseEvent e) {
174                                         lblFotoCargar.setVisible(false);
175
176                                 }
177                         });
178                         btnCargarSaldo.addActionListener(new ActionListener() {
179                                 @Override
180                                 public void actionPerformed(ActionEvent arg0) {
181
182                                         Frame vista = new RecargarSaldoGUI(userlog);
183                                         vista.setAlwaysOnTop(true);
184                                         vista.setVisible(true);
185                                         dispose();
186
187                                 }
188                         });
189
190                         btnCargarSaldo.setBounds(45, 436, 422, 83);
191                         jContentPane.add(btnCargarSaldo);
192
193                         ImageIcon icon = new ImageIcon("imagenes/miniatura.png");
194                         lblFotoCargar = new JLabel(icon);
195                         lblFotoCargar.setVisible(false);
196                         lblFotoCargar.setBounds(485, 245, 259, 155);
197                         jContentPane.add(lblFotoCargar);
198
199                         ImageIcon icon2 = new ImageIcon("imagenes/makebet.png");
200                         lblFotoMakeBet = new JLabel(icon2);
201                         lblFotoMakeBet.setVisible(false);
202                         lblFotoMakeBet.setBounds(485, 245, 259, 155);
203                         jContentPane.add(lblFotoMakeBet);
204
205                         ImageIcon icon3 = new ImageIcon("imagenes/anularbet.png");
206                         lblFotoAnular = new JLabel(icon3);
207                         lblFotoAnular.setVisible(false);
208                         lblFotoAnular.setBounds(485, 245, 259, 155);
209                         jContentPane.add(lblFotoAnular);
210
211                         ImageIcon icon4 = new ImageIcon("imagenes/historial.png");
212                         lblFotoHistorial = new JLabel(icon4);
213                         lblFotoHistorial.setVisible(false);
214                         lblFotoHistorial.setBounds(485, 245, 259, 155);
215                         jContentPane.add(lblFotoHistorial);
216
217                         ImageIcon icon5 = new ImageIcon("imagenes/perfil.png");
218                         lblFotoPerfil = new JLabel(icon5);
219                         lblFotoPerfil.setVisible(false);
220                         lblFotoPerfil.setBounds(485, 245, 259, 155);
221                         jContentPane.add(lblFotoPerfil);
222
223                         JPanel panel_1 = new JPanel();
224                         panel_1.setBackground(new Color(0, 0, 128));
225                         panel_1.setBounds(554, 34, 145, 34);
226                         jContentPane.add(panel_1);
227                         panel_1.setLayout(null);
228                         panel_1.add(getlblSaldo());
229                 }
230                 return jContentPane;
231         }
232
233         /**
234          * This method initializes boton1
235          * 
236          * @return javax.swing.JButton
237          */
238         private JButton getBoton2() {
239
240                 // btnModificar.setText(ResourceBundle.getBundle("Etiquetas").getString("Show/EditProfile"));
241                 btnModificar.setText("Show/EditProfile");
242                 btnModificar.addActionListener(new ActionListener() {
243                         @Override
244                         public void actionPerformed(ActionEvent e) {
245
246                                 Frame reg = new ModificarDatosGUI(userlog);
247                                 reg.setAlwaysOnTop(true);
248                                 reg.setVisible(true);
249                                 dispose();
250                         }
251                 });
252
253                 return btnModificar;
254         }
255
256         /**
257          * This method initializes boton2
258          * 
259          * @return javax.swing.JButton
260          */
261 //      private JButton getBoton3() {
262 //              if (jButtonQueryQueries == null) {
263 //                      jButtonQueryQueries = new JButton();
264 //                      jButtonQueryQueries.setText(ResourceBundle.getBundle("Etiquetas").getString("QueryQueries"));
265 //                      jButtonQueryQueries.addActionListener(new java.awt.event.ActionListener() {
266 //                              @Override
267 //                              public void actionPerformed(java.awt.event.ActionEvent e) {
268 //                                      JFrame a = new FindQuestionsGUI();
269 //                                      a.setAlwaysOnTop(true);
270 //                                      a.setVisible(true);
271 //                                      a.setVisible(true);
272 //                              }
273 //                      });
274 //              }
275 //              return jButtonQueryQueries;
276 //      }
277
278         private JLabel getLblNewLabel() {
279                 if (jLabelSelectOption == null) {
280 //                      jLabelSelectOption = new JLabel(ResourceBundle.getBundle("Etiquetas").getString("SelectOption"));
281                         jLabelSelectOption = new JLabel("SelectOption");
282                         jLabelSelectOption.setBounds(0, 12, 536, 97);
283                         jLabelSelectOption.setFont(new Font("Tahoma", Font.BOLD, 13));
284                         jLabelSelectOption.setForeground(Color.BLACK);
285                         jLabelSelectOption.setHorizontalAlignment(SwingConstants.CENTER);
286                 }
287                 return jLabelSelectOption;
288         }
289
290         private JRadioButton getRdbtnNewRadioButton() {
291                 if (rdbtnNewRadioButton == null) {
292                         rdbtnNewRadioButton = new JRadioButton("English");
293                         rdbtnNewRadioButton.setBackground(Color.WHITE);
294                         rdbtnNewRadioButton.addActionListener(new ActionListener() {
295                                 @Override
296                                 public void actionPerformed(ActionEvent e) {
297                                         Locale.setDefault(new Locale("en"));
298                                         System.out.println("Locale: " + Locale.getDefault());
299                                         redibujar();
300                                 }
301                         });
302                         buttonGroup.add(rdbtnNewRadioButton);
303                 }
304                 return rdbtnNewRadioButton;
305         }
306
307         private JRadioButton getRdbtnNewRadioButton_1() {
308                 if (rdbtnNewRadioButton_1 == null) {
309                         rdbtnNewRadioButton_1 = new JRadioButton("Euskara");
310                         rdbtnNewRadioButton_1.setBackground(Color.WHITE);
311                         rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
312                                 @Override
313                                 public void actionPerformed(ActionEvent arg0) {
314                                         Locale.setDefault(new Locale("eus"));
315                                         System.out.println("Locale: " + Locale.getDefault());
316                                         redibujar();
317                                 }
318                         });
319                         buttonGroup.add(rdbtnNewRadioButton_1);
320                 }
321                 return rdbtnNewRadioButton_1;
322         }
323
324         private JRadioButton getRdbtnNewRadioButton_2() {
325                 if (rdbtnNewRadioButton_2 == null) {
326                         rdbtnNewRadioButton_2 = new JRadioButton("Castellano");
327                         rdbtnNewRadioButton_2.setBackground(Color.WHITE);
328                         rdbtnNewRadioButton_2.addActionListener(new ActionListener() {
329                                 @Override
330                                 public void actionPerformed(ActionEvent e) {
331                                         Locale.setDefault(new Locale("es"));
332                                         System.out.println("Locale: " + Locale.getDefault());
333                                         redibujar();
334                                 }
335                         });
336                         buttonGroup.add(rdbtnNewRadioButton_2);
337                 }
338                 return rdbtnNewRadioButton_2;
339         }
340
341         private JPanel getPanel() {
342                 if (panel == null) {
343                         panel = new JPanel();
344                         panel.setBackground(Color.WHITE);
345                         panel.setBounds(0, 543, 536, 40);
346                         panel.add(getRdbtnNewRadioButton_1());
347                         panel.add(getRdbtnNewRadioButton_2());
348                         panel.add(getRdbtnNewRadioButton());
349                 }
350                 return panel;
351         }
352
353         private void redibujar() {
354 //              jLabelSelectOption.setText(ResourceBundle.getBundle("Etiquetas").getString("SelectOption"));
355 //              btnBet.setText(ResourceBundle.getBundle("Etiquetas").getString("MakeBet"));
356 //              btnModificar.setText(ResourceBundle.getBundle("Etiquetas").getString("Show/EditProfile"));
357 //              btnHistorial.setText(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.btnHistorial.text"));
358 //              lblSaldo.setText(
359 //                              ResourceBundle.getBundle("Etiquetas").getString("MainGUI.lblSaldo") + " " + userlog.getBalance() + "€");
360 //              this.setTitle(ResourceBundle.getBundle("Etiquetas").getString("MainTitle"));
361 //              btnAnularApuesta.setText(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.btnAnularApuesta.text"));
362 //              btnCargarSaldo.setText(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.cargarSaldo"));
363
364                 jLabelSelectOption.setText("SelectOption");
365                 btnBet.setText("Bet");
366                 btnModificar.setText("Show/EditProfile");
367                 btnHistorial.setText("CheckHistory");
368                 lblSaldo.setText("Balance" + " " + userlog.getBalance() + "€");
369                 this.setTitle("MainTitle");
370                 btnAnularApuesta.setText("Cancel Bet");
371                 btnCargarSaldo.setText("Load Balance");
372
373         }
374
375         public void close() {
376                 this.setVisible(false);
377         }
378
379         private JButton getBtnBet() {
380                 if (btnBet == null) {
381                         btnBet = new JButton();
382                         btnBet.addMouseListener(new MouseAdapter() {
383                                 @Override
384                                 public void mouseEntered(MouseEvent e) {
385                                         lblFotoMakeBet.setVisible(true);
386                                 }
387
388                                 @Override
389                                 public void mouseExited(MouseEvent e) {
390                                         lblFotoMakeBet.setVisible(false);
391
392                                 }
393                         });
394                         btnBet.setBounds(45, 184, 422, 85);
395                         btnBet.addActionListener(new ActionListener() {
396                                 @Override
397                                 public void actionPerformed(ActionEvent arg0) {
398                                         Frame reg = new CreateBetGUI(userlog);
399                                         reg.setAlwaysOnTop(true);
400                                         reg.setVisible(true);
401                                         dispose();
402                                 }
403                         });
404                         // btnBet.setText(ResourceBundle.getBundle("Etiquetas").getString("MakeBet"));
405                         // //$NON-NLS-1$ //$NON-NLS-2$
406                         btnBet.setText("MakeBet");
407                 }
408                 return btnBet;
409         }
410
411         private JLabel getlblSaldo() {
412                 if (lblSaldo == null) {
413 //                      lblSaldo = new JLabel(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.lblSaldo") + " "
414 //                                      + userlog.getBalance() + "€");
415                         lblSaldo = new JLabel("Balance" + " " + userlog.getBalance() + "€");
416                         lblSaldo.setBounds(8, 5, 205, 19);
417                         lblSaldo.setFont(new Font("Tahoma", Font.BOLD, 14));
418                         lblSaldo.setForeground(Color.WHITE);
419                 }
420                 return lblSaldo;
421         }
422
423         private JButton getBtnAnularApuesta() {
424                 if (btnAnularApuesta == null) {
425                         btnAnularApuesta = new JButton();
426                         btnAnularApuesta.addMouseListener(new MouseAdapter() {
427                                 @Override
428                                 public void mouseEntered(MouseEvent e) {
429                                         lblFotoAnular.setVisible(true);
430                                 }
431
432                                 @Override
433                                 public void mouseExited(MouseEvent e) {
434                                         lblFotoAnular.setVisible(false);
435
436                                 }
437                         });
438                         btnAnularApuesta.addActionListener(new ActionListener() {
439                                 @Override
440                                 public void actionPerformed(ActionEvent e) {
441
442                                         Frame reg = new AnularApuestaGUI(userlog);
443                                         reg.setAlwaysOnTop(true);
444                                         reg.setVisible(true);
445                                         dispose();
446
447                                 }
448                         });
449 //                      btnAnularApuesta.setText(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.btnAnularApuesta.text")); //$NON-NLS-1$ //$NON-NLS-2$
450                         btnAnularApuesta.setText("Cancel Bet");
451                         btnAnularApuesta.setBounds(45, 352, 422, 83);
452                 }
453                 return btnAnularApuesta;
454         }
455 }
456 // @jve:decl-index=0:visual-constraint="0,0"