From 95805c3efa5f7c51426c5e38bd548c9175f3f92c Mon Sep 17 00:00:00 2001 From: Guillermo Date: Mon, 11 Nov 2019 22:31:10 +0100 Subject: [PATCH] Corrigiendo bugs listeners --- src/VistaControlador/Controlador.java | 33 ++++++++++++--------------- src/VistaControlador/Menu.java | 4 ---- src/VistaControlador/Vista.java | 13 ++++++----- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/VistaControlador/Controlador.java b/src/VistaControlador/Controlador.java index 56db407..20a7326 100644 --- a/src/VistaControlador/Controlador.java +++ b/src/VistaControlador/Controlador.java @@ -2,14 +2,12 @@ package VistaControlador; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - import javax.swing.JCheckBox; import javax.swing.JOptionPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import Logica.Gestion; -import Logica.Transaccion; public class Controlador implements ActionListener,ChangeListener{ @@ -18,7 +16,7 @@ public class Controlador implements ActionListener,ChangeListener{ this.vista=vista; this.aniadirListeners(); } - @Override + public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals(this.vista.boton.getActionCommand())) { String nombre=JOptionPane.showInputDialog("Introduce un nuevo gasto o ingreso"); @@ -33,11 +31,10 @@ public class Controlador implements ActionListener,ChangeListener{ } try { - this.vista.aniadirElemento(nombre, Integer.parseInt(dinero)); + this.vista.aniadirElemento(nombre, Integer.parseInt(dinero),this); this.vista.menu.total.setText(String.valueOf(Gestion.getTotal())); this.vista.menu.total.revalidate(); this.vista.menu.total.repaint(); - this.aniadirListeners(); }catch (NumberFormatException ex) { JOptionPane.showMessageDialog(null, "Debe introducir un numero", "error", JOptionPane.WARNING_MESSAGE); } @@ -45,33 +42,31 @@ public class Controlador implements ActionListener,ChangeListener{ JCheckBox pulsado=(JCheckBox)e.getSource(); for(int i=0;i transacciones; @@ -20,7 +21,6 @@ public class Vista extends JPanel{ JScrollPane panel; Menu menu; public Vista(Menu menu) { - //this.setLayout(new ); this.transacciones=new LinkedList(); this.menu=menu; this.x=100; @@ -30,22 +30,23 @@ public class Vista extends JPanel{ this.cuadro=new JPanel(); this.panel=new JScrollPane(cuadro); this.panel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - this.panel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + this.panel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); cuadro.setPreferredSize(new Dimension(x, y)); panel.setPreferredSize(new Dimension(100,200)); panel.setVisible(true); this.add(panel); - this.aniadirElemento("asdfa", 0); } - public void aniadirElemento(String nombre, int dinero) { + public void aniadirElemento(String nombre, int dinero, Controlador controlador) { Transaccion transaccion=new Transaccion(nombre, dinero); this.gestiones.aniadirGasto(transaccion); JCheckBox check=new JCheckBox(transaccion.toString()); + check.setSelected(true); + check.setSize(new Dimension(x,Vista.altocheck)); + check.addActionListener(controlador); this.transacciones.add(check); this.cuadro.add(check); - this.y+=28; - //System.out.println(this.y); + this.y+=Vista.altocheck; cuadro.setPreferredSize(new Dimension(x, y)); this.revalidate(); this.repaint();