diff --git a/bin/.gitignore b/bin/.gitignore index e809c4c..f9897f2 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,2 +1,3 @@ /VistaControlador/ /PedirDatos/ +/Logica/ diff --git a/src/Logica/Gestion.java b/src/Logica/Gestion.java index 9d74c1e..5d9ccd5 100644 --- a/src/Logica/Gestion.java +++ b/src/Logica/Gestion.java @@ -12,21 +12,17 @@ public class Gestion{ Gestion.total=0; } - public void aniadirGasto(String nombre, int dinero) { - this.gestiones.add(new Transaccion(nombre, dinero)); - this.suma+=dinero; - Gestion.total+=total; - } - public void aniadirGasto(Transaccion transaccion) { this.gestiones.add(transaccion); + this.suma+=transaccion.getDinero(); + Gestion.total+=transaccion.getDinero(); } public int getSuma() { return this.suma; } - public int getTotal() { + public static int getTotal() { return Gestion.total; } @@ -36,8 +32,15 @@ public class Gestion{ public void alterarVisibilidad(boolean visibilidad, int elemento) { if(this.gestiones.get(elemento).alterarVisivilidad(visibilidad)) { - this.suma-=this.gestiones.get(elemento).getDinero(); - Gestion.total-=this.gestiones.get(elemento).getDinero(); + if(this.gestiones.get(elemento).getVisivilidad()) { + this.suma+=this.gestiones.get(elemento).getDinero(); + Gestion.total+=this.gestiones.get(elemento).getDinero(); + }else { + this.suma-=this.gestiones.get(elemento).getDinero(); + Gestion.total-=this.gestiones.get(elemento).getDinero(); + } + } } + } diff --git a/src/VistaControlador/Controlador.java b/src/VistaControlador/Controlador.java index dcd9237..56db407 100644 --- a/src/VistaControlador/Controlador.java +++ b/src/VistaControlador/Controlador.java @@ -2,9 +2,16 @@ package VistaControlador; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.JOptionPane; -public class Controlador implements 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{ private Vista vista; public Controlador(Vista vista) { @@ -13,28 +20,58 @@ public class Controlador implements ActionListener{ } @Override public void actionPerformed(ActionEvent e) { - String nombre=JOptionPane.showInputDialog("Introduce un nuevo gasto o ingreso"); - if(nombre.equals("")) { - JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); - return; - } - String dinero=JOptionPane.showInputDialog("Introduce a cuanto asciende"); - if(dinero.equals("")) { - JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); - return; + if(e.getActionCommand().equals(this.vista.boton.getActionCommand())) { + String nombre=JOptionPane.showInputDialog("Introduce un nuevo gasto o ingreso"); + if(nombre.equals("")) { + JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); + return; + } + String dinero=JOptionPane.showInputDialog("Introduce a cuanto asciende"); + if(dinero.equals("")) { + JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); + return; + } + + try { + this.vista.aniadirElemento(nombre, Integer.parseInt(dinero)); + 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); + } + }else { + JCheckBox pulsado=(JCheckBox)e.getSource(); + for(int i=0;i transacciones; JPanel cuadro; JScrollPane panel; - public Vista(JFrame padre) { + Menu menu; + public Vista(Menu menu) { + this.transacciones=new LinkedList(); + this.menu=menu; this.x=100; this.boton=new JButton("aniadir"); this.gestiones=new Gestion(); @@ -30,13 +35,13 @@ public class Vista extends JPanel{ panel.setVisible(true); this.add(panel); this.aniadirElemento("asdfa", 0); - this.padre=padre; } public void aniadirElemento(String nombre, int dinero) { Transaccion transaccion=new Transaccion(nombre, dinero); this.gestiones.aniadirGasto(transaccion); JCheckBox check=new JCheckBox(transaccion.toString()); + this.transacciones.add(check); this.cuadro.add(check); this.y+=28; //System.out.println(this.y);