ISBets21MAUBRY
3cf4057e97448d401b49261033b8ab566105944e
ISBets21MAUBRY / eclipse-workspace / ISBets21MAUBRY / src / main / java / gui / AnularApuestaGUI.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
package gui; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Rectangle; import java.awt.SystemColor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Vector; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import businessLogic.BLFacade; import domain.Bet; import domain.RegularUser; public class AnularApuestaGUI extends JFrame { private JPanel contentPane; private JScrollPane scrollPaneApuestas = new JScrollPane(); private JTable tabla; private String[] nombresColumnas = { "Fecha", "Evento", "Pregunta", "Apuesta a ", "Cant. apostada", "Cuota", "" }; private DefaultTableModel tableModelApuestas = new DefaultTableModel(null, nombresColumnas) { @Override public boolean isCellEditable(int row, int column) { return false; } }; private static BLFacade facade = LoginGUI.getBusinessLogic(); private RegularUser userlog; private JButton btnAtras; private JLabel lblApuestas; private JLabel lblInfo; private JSeparator separator; private JLabel lblSaldo; private RegularUser newUserActualizado; private JLabel lblNewLabel_1; public AnularApuestaGUI(RegularUser ru) { getContentPane().setBackground(Color.WHITE); userlog = ru; newUserActualizado = ru; // setTitle(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.btnAnularApuesta.text") // + " " + userlog.getUserName()); setTitle("btnAnularApuesta" + " " + userlog.getUserName()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 1100, 500); getContentPane().setLayout(null); JButton btnEliminar = new JButton("Anular"); btnEliminar.setName("Anular"); Vector<Bet> apuestasUsuario = facade.getApuestasAbiertas(userlog); Vector<Bet> apuestasAbiertas = new Vector<Bet>(); for (Bet bet : apuestasUsuario) { if (bet.getEstadoApuesta().equals("Pendiente")) { Vector<Object> row = new Vector<Object>(); row.add(bet.getForecast().getQuestion().getEvent().getEventDate().toString().substring(0, 11)); row.add(bet.getForecast().getQuestion().getEvent().getDescription()); row.add(bet.getForecast().getQuestion().getQuestion()); row.add(bet.getForecast().getForecast()); row.add(bet.getAmount()); row.add(bet.getForecast().getFee()); row.addElement(btnEliminar); apuestasAbiertas.addElement(bet); tableModelApuestas.addRow(row); } } // OVERRIDE DE METODO PARA QUE SE AJUSTEN AUTOMATICAMENTE LAS COLUMNAS DE LA // TABLA SEGUN EL CONTENIDO tabla = new JTable(tableModelApuestas) { @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component component = super.prepareRenderer(renderer, row, column); int rendererWidth = component.getPreferredSize().width; TableColumn tableColumn = getColumnModel().getColumn(column); tableColumn.setPreferredWidth( Math.max(rendererWidth + getIntercellSpacing().width, tableColumn.getPreferredWidth())); return component; } }; tabla.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(row % 2 != 0 ? new Color(233, 233, 233) : Color.WHITE); return c; } }); tabla.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { int column = tabla.getColumnModel().getColumnIndexAtX(ev.getX()); int row = ev.getY() / tabla.getRowHeight(); if (row < tabla.getRowCount() && row >= 0 && column < tabla.getColumnCount() && column >= 0) { Object value = tabla.getValueAt(row, column); if (value instanceof JButton) { ((JButton) value).doClick(); JButton boton = (JButton) value; try { int i = tabla.getSelectedRow(); Bet apu = apuestasAbiertas.get(i); // int dialogButton = JOptionPane.YES_NO_OPTION; // JOptionPane.showConfirmDialog(getContentPane(), "¿Seguro que quieres anular la apuesta?", // "CUIDADO!", dialogButton); // if (dialogButton == JOptionPane.YES_OPTION) { // System.out.println("CLIC EN SI"); System.out.println("Anulando la apuesta: " + apu.getForecast().getForecast() + " / " + apu.getForecast().getQuestion() + " / " + apu.getForecast().getQuestion().getEvent().getDescription() + "de la tabla"); tableModelApuestas.removeRow(row); apuestasAbiertas.remove(i); if (facade.anularApuesta(apu)) { JOptionPane.showMessageDialog(getContentPane(), "La apuesta a " + apu.getForecast().getForecast() + " ha sido anulada. \nEl importe de " + apu.getAmount() + "€" + " será reintegrado inmediatamente..."); System.out.println("APUESTA ANULADA"); // lblSaldo.setText(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.lblSaldo") // + " " + (newUserActualizado.getBalance() + apu.getAmount()) + "€"); lblSaldo.setText( "Balance" + " " + (newUserActualizado.getBalance() + apu.getAmount()) + "€"); } // } // if (dialogButton == JOptionPane.NO_OPTION) { // System.out.println("CLIC EN NO"); // remove(dialogButton); // } newUserActualizado = facade.getRegularUserByUsername(userlog.getUserName()); } catch (Exception e) { } } } } }); tabla.setDefaultRenderer(Object.class, new Render()); scrollPaneApuestas.setBounds(new Rectangle(40, 190, 996, 119)); scrollPaneApuestas.setViewportView(tabla); this.getContentPane().add(scrollPaneApuestas); btnAtras = new JButton(); btnAtras.setForeground(Color.WHITE); btnAtras.setFont(new Font("Dialog", Font.BOLD, 14)); btnAtras.setBackground(SystemColor.controlShadow); // btnAtras.setText(ResourceBundle.getBundle("Etiquetas").getString("Close")); btnAtras.setText("Close"); btnAtras.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { RegularUser usuarioActualizado = facade.getRegularUserByUsername(userlog.getUserName()); JFrame a = new MainGUI(usuarioActualizado); a.setAlwaysOnTop(true); a.setVisible(true); dispose(); } }); btnAtras.setBounds(52, 376, 99, 26); getContentPane().add(btnAtras); lblApuestas = new JLabel("Apuestas abiertas:"); lblApuestas.setBounds(40, 156, 135, 16); getContentPane().add(lblApuestas); lblInfo = new JLabel( "Aquí podrás cancelar una apuesta que aún sigue en curso. Se te devolverá el dinero apostado."); lblInfo.setBounds(66, 48, 666, 47); getContentPane().add(lblInfo); separator = new JSeparator(); separator.setBounds(64, 94, 535, 26); getContentPane().add(separator); JPanel panel = new JPanel(); panel.setBackground(new Color(0, 0, 128)); panel.setBounds(655, 26, 136, 36); getContentPane().add(panel); panel.setLayout(null); // lblSaldo = new JLabel(ResourceBundle.getBundle("Etiquetas").getString("MainGUI.lblSaldo") //$NON-NLS-1$ //$NON-NLS-2$ // + " " + userlog.getBalance() + "€"); lblSaldo = new JLabel("Balance" //$NON-NLS-1$ //$NON-NLS-2$ + " " + userlog.getBalance() + "€"); lblSaldo.setBounds(10, 8, 197, 19); panel.add(lblSaldo); lblSaldo.setFont(new Font("Tahoma", Font.BOLD, 14)); lblSaldo.setForeground(Color.WHITE); ImageIcon icon = new ImageIcon("imagenes/info.png"); lblNewLabel_1 = new JLabel(icon); lblNewLabel_1.setBounds(23, 48, 55, 40); getContentPane().add(lblNewLabel_1); } } |
Commits for ISBets21MAUBRYeclipse-workspace/ISBets21MAUBRY/src/main/java/gui/AnularApuestaGUI.java
Revision | Author | Commited | Message |
---|---|---|---|
3cf405 ... | porkipig | Sun 16 May, 2021 19:27:29 +0000 | Iteración 3(Versión sin idiomas) |