4 import java.awt.Component;
6 import java.awt.Rectangle;
7 import java.awt.SystemColor;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.awt.print.PrinterException;
11 import java.util.Vector;
13 import javax.swing.ImageIcon;
14 import javax.swing.JButton;
15 import javax.swing.JFrame;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18 import javax.swing.JScrollPane;
19 import javax.swing.JSeparator;
20 import javax.swing.JTable;
21 import javax.swing.table.DefaultTableCellRenderer;
22 import javax.swing.table.DefaultTableModel;
23 import javax.swing.table.TableCellRenderer;
24 import javax.swing.table.TableColumn;
26 import businessLogic.BLFacade;
28 import domain.RegularUser;
30 public class HistorialApuestasGUI extends JFrame {
32 private JScrollPane scrollPaneApuestas = new JScrollPane();
33 private JScrollPane scrollPaneApuestas2 = new JScrollPane();
36 private JTable tabla2;
38 private String[] nombresColumnas = { "Fecha", "Evento", "Pregunta", "Apuesta a ", "Cant. apostada", "Cuota",
40 private String[] nombresColumnas2 = { "Fecha", "Evento", "Pregunta", "Apuesta a", "Estado", "Pron. ganador",
41 "Cant. apostada", "Cuota", "Ganado (Beneficio)" };
43 // private String[][] datosFilas = {
45 // { "Bryan", "Sanchez", "23", "Español", "170" }, { "Mauri", "Contreras", "22", "Peruano", "150" },
46 // { "Melisa", "Fernandez", "21", "Español", "150" }, { "Jorshua", "Dickensen", "23", "Peruano", "160" },
47 // { "Leire", "Cartagena", "20", "Español", "150" }, { "Kofi", "Darko", "21", "Africano", "160" },
51 private DefaultTableModel tableModelApuestas = new DefaultTableModel(null, nombresColumnas) {
53 public boolean isCellEditable(int row, int column) {
58 private DefaultTableModel tableModelApuestas2 = new DefaultTableModel(null, nombresColumnas2) {
60 public boolean isCellEditable(int row, int column) {
64 // private String estadoApuesta = "";
66 private RegularUser userlog;
68 private static BLFacade facade = LoginGUI.getBusinessLogic();
69 private JLabel lblInfo;
71 public HistorialApuestasGUI(RegularUser ru) {
72 getContentPane().setBackground(Color.WHITE);
75 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
76 // setTitle(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.btnHistorial.text")
77 // + " " + userlog.getUserName());
78 setTitle("btnHistorial"
80 + userlog.getUserName());
82 getContentPane().setLayout(null);
83 this.setSize(1388, 641);
85 Vector<Bet> apuestasUsuario = facade.getApuestasByUser(userlog);
87 /* TABLA 1 APUESTAS ABIERTAS */
89 // Introducir datos de las dos tablas a los tablemodel, dependiendo de si la
90 // apuesta esta cerrada o no
91 for (Bet b : apuestasUsuario) {
93 // if (b.getForecast().getForecast().equals(b.getForecast().getQuestion().getResult())) {
94 // estadoApuesta = "Ganada";
96 // estadoApuesta = "Perdida";
99 if (b.getForecast().getQuestion().getResult() == null && b.getEstadoApuesta().equals("Anulada") == false) { // PRIMERA
103 Vector<Object> row = new Vector<Object>();
104 row.add(b.getForecast().getQuestion().getEvent().getEventDate().toString().substring(0, 11));
105 row.add(b.getForecast().getQuestion().getEvent().getDescription());
106 row.add(b.getForecast().getQuestion().getQuestion());
107 row.add(b.getForecast().getForecast());
108 row.add(b.getAmount());
109 row.add(b.getForecast().getFee());
110 row.add(b.getEstadoApuesta());
112 tableModelApuestas.addRow(row);
113 } else { // SEGUNDA TABLA APUESTAS CERRADAS
114 Vector<Object> row = new Vector<Object>();
115 row.add(b.getForecast().getQuestion().getEvent().getEventDate().toString().substring(0, 11));
116 row.add(b.getForecast().getQuestion().getEvent().getDescription());
117 row.add(b.getForecast().getQuestion().getQuestion());
118 row.add(b.getForecast().getForecast());
119 row.add(b.getEstadoApuesta());
120 row.add(b.getForecast().getQuestion().getResult());
121 row.add(b.getAmount());
122 row.add(b.getForecast().getFee());
124 if (b.getEstadoApuesta().equals("Perdida")) {
127 } else if (b.getEstadoApuesta().equals("Anulada")) {
131 if (Float.toString((b.getAmount() * b.getForecast().getFee() - b.getAmount())).equals("0.0")) {
132 row.add(b.getAmount() * b.getForecast().getFee());
135 row.add(b.getAmount() * b.getForecast().getFee() + " ("
136 + Float.toString((b.getAmount() * b.getForecast().getFee() - b.getAmount())) + ") ");
140 tableModelApuestas2.addRow(row);
145 // OVERRIDE DE METODO PARA QUE SE AJUSTEN AUTOMATICAMENTE LAS COLUMNAS DE LA
146 // TABLA SEGUN EL CONTENIDO
147 tabla = new JTable(tableModelApuestas) {
149 public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
150 Component component = super.prepareRenderer(renderer, row, column);
151 int rendererWidth = component.getPreferredSize().width;
152 TableColumn tableColumn = getColumnModel().getColumn(column);
153 tableColumn.setPreferredWidth(
154 Math.max(rendererWidth + getIntercellSpacing().width, tableColumn.getPreferredWidth()));
160 // COLOR DE LAS FILAS DE LA TABLA GRIS Y BLANCO
161 tabla.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
163 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
164 boolean hasFocus, int row, int column) {
165 final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
168 c.setBackground(row % 2 == 0 ? new Color(233, 233, 233) : Color.WHITE);
174 scrollPaneApuestas.setBounds(new Rectangle(35, 148, 958, 119));
175 scrollPaneApuestas.setViewportView(tabla);
176 this.getContentPane().add(scrollPaneApuestas);
178 /* TABLA 2 APUESTAS CERRADAS */
180 // OVERRIDE DE METODO PARA QUE SE AJUSTEN AUTOMATICAMENTE LAS COLUMNAS DE LA
181 // TABLA SEGUN EL CONTENIDO
182 tabla2 = new JTable(tableModelApuestas2) {
184 public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
185 Component component = super.prepareRenderer(renderer, row, column);
186 int rendererWidth = component.getPreferredSize().width;
187 TableColumn tableColumn = getColumnModel().getColumn(column);
188 tableColumn.setPreferredWidth(
189 Math.max(rendererWidth + getIntercellSpacing().width, tableColumn.getPreferredWidth()));
195 // COLOR DE LAS FILAS DE LA TABLA GRIS Y BLANCO
196 tabla2.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
198 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
199 boolean hasFocus, int row, int column) {
200 final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
203 c.setBackground(row % 2 == 0 ? new Color(233, 233, 233) : Color.WHITE);
209 scrollPaneApuestas2.setBounds(new Rectangle(35, 347, 1089, 119));
210 scrollPaneApuestas2.setViewportView(tabla2);
212 getContentPane().add(scrollPaneApuestas2);
214 /* BOTON ATRAS, BOTONES DESCARGAR TABLA Y LABELS */
216 // JButton btnAtras = new JButton(ResourceBundle.getBundle("Etiquetas").getString("Close"));
217 JButton btnAtras = new JButton("Close");
218 btnAtras.setFont(new Font("Dialog", Font.BOLD, 14));
219 btnAtras.setForeground(Color.WHITE);
220 btnAtras.setBackground(SystemColor.controlShadow);
222 btnAtras.addActionListener(new ActionListener() {
224 public void actionPerformed(ActionEvent arg0) {
226 JFrame a = new MainGUI(userlog);
227 a.setAlwaysOnTop(true);
233 btnAtras.setBounds(35, 537, 99, 26);
234 getContentPane().add(btnAtras);
236 JLabel lblApuestasAbiertas = new JLabel("Apuestas abiertas");
237 lblApuestasAbiertas.setBounds(49, 120, 147, 16);
238 getContentPane().add(lblApuestasAbiertas);
240 JLabel lblApuestasCerradas = new JLabel("Apuestas cerradas");
241 lblApuestasCerradas.setBounds(49, 314, 147, 16);
242 getContentPane().add(lblApuestasCerradas);
244 JButton btnDescargarTabla = new JButton("Descargar tabla");
245 btnDescargarTabla.setFont(new Font("Dialog", Font.BOLD, 14));
246 btnDescargarTabla.setForeground(Color.WHITE);
247 btnDescargarTabla.setBackground(SystemColor.textHighlight);
248 btnDescargarTabla.addActionListener(new ActionListener() {
250 public void actionPerformed(ActionEvent e) {
253 System.out.println("IMPRIMIDA LA TABLA");
254 setAlwaysOnTop(false);
256 } catch (PrinterException e1) {
257 e1.printStackTrace();
261 btnDescargarTabla.setBounds(1003, 193, 159, 26);
262 getContentPane().add(btnDescargarTabla);
264 JButton btnDescargarTabla2 = new JButton("Descargar tabla");
265 btnDescargarTabla2.setForeground(Color.WHITE);
266 btnDescargarTabla2.setFont(new Font("Dialog", Font.BOLD, 14));
267 btnDescargarTabla2.setBackground(SystemColor.textHighlight);
268 btnDescargarTabla2.addActionListener(new ActionListener() {
270 public void actionPerformed(ActionEvent arg0) {
272 System.out.println("IMPRIMIDA LA TABLA 2");
273 setAlwaysOnTop(false);
275 } catch (PrinterException e1) {
276 e1.printStackTrace();
280 btnDescargarTabla2.setBounds(1136, 401, 165, 26);
281 getContentPane().add(btnDescargarTabla2);
283 lblInfo = new JLabel(
284 "Aquí podrás encontrar el historial de tus apuestas, tanto las que están en curso como las que están cerradas.");
285 lblInfo.setBounds(100, 44, 748, 16);
286 getContentPane().add(lblInfo);
288 JSeparator separator = new JSeparator();
289 separator.setBounds(94, 72, 631, 15);
290 getContentPane().add(separator);
292 ImageIcon icon = new ImageIcon("imagenes/info.png");
293 JLabel lblNewLabel = new JLabel(icon);
294 lblNewLabel.setBounds(68, 37, 30, 30);
295 getContentPane().add(lblNewLabel);
297 JPanel panel = new JPanel();
298 panel.setBackground(new Color(0, 0, 128));
299 panel.setBounds(895, 37, 141, 30);
300 getContentPane().add(panel);
302 // JLabel lblSaldo = new JLabel(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.lblSaldo") //$NON-NLS-1$ //$NON-NLS-2$
303 JLabel lblSaldo = new JLabel("Balance" //$NON-NLS-1$ //$NON-NLS-2$
304 + " " + userlog.getBalance() + "€");
306 lblSaldo.setFont(new Font("Tahoma", Font.BOLD, 14));
307 lblSaldo.setForeground(Color.WHITE);