diff --git a/src/Logica/Meses.java b/src/Logica/Meses.java index 7eea92c..d8e2d80 100644 --- a/src/Logica/Meses.java +++ b/src/Logica/Meses.java @@ -46,9 +46,11 @@ private ArrayList meses; public void elegirMes(int anio, Month mes) { for(int i = 0; i < this.meses.size(); i++) { if(this.meses.get(i).getAnio()==anio && this.meses.get(i).getMes().equals(mes)) { - this.mesActual = 0; + this.mesActual = i; + return; } } + this.meses.add(new Mes(new ArrayList(), anio, mes)); } public ArrayList getGestionesActuales(){ diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index 4f5f941..315705c 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -4,6 +4,8 @@ import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.time.LocalDate; +import java.time.Month; +import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; @@ -23,6 +25,7 @@ public class Menu extends JFrame{ protected VistaAniadirVisualizar gastos; protected VistaPanelLateral panel; Meses meses; + ArrayList pestanias; protected Gestion datosGastos; protected Gestion datosIngresos; public Menu() { @@ -30,8 +33,8 @@ public class Menu extends JFrame{ meses.aniadirGestion("Ingresos", LocalDate.now().getYear(), LocalDate.now().getMonth()); meses.aniadirGestion("Gastos", LocalDate.now().getYear(), LocalDate.now().getMonth()); VistaAniadirVisualizar.setPanelLateral(panel); - this.datosGastos = new Gestion(); - this.datosIngresos = new Gestion(); + //this.datosGastos = new Gestion(); + //this.datosIngresos = new Gestion(); this.setLayout(new GridBagLayout()); GridBagConstraints constrain = new GridBagConstraints(); this.panel = new VistaPanelLateral(constrain); @@ -65,4 +68,28 @@ public class Menu extends JFrame{ this.add(this.panel); } + + + private void iniciarMes(int anio, Month mes) { + this.meses=new Meses(); + meses.aniadirGestion("Ingresos", anio, mes); + meses.aniadirGestion("Gastos", anio, mes); + this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(0),true)); + this.pestanias.add(new VistaAniadirVisualizar(this,meses.getGestionesActuales().get(1),false)); + } + + private void cargarGestiones(int anio, Month mes) { + this.meses.elegirMes(anio, mes); + if(this.meses.getGestionesActuales().size() == 0) { + this.iniciarMes(anio, mes); + } + } + + private void cargarPestanias() { + this.pestania.removeAll(); + for(VistaAniadirVisualizar vista:this.pestanias) { + this.pestania.add(vista); + } + } + } diff --git a/src/VistaControlador/VistaPanelLateral.java b/src/VistaControlador/VistaPanelLateral.java index 2120abf..a908ff4 100644 --- a/src/VistaControlador/VistaPanelLateral.java +++ b/src/VistaControlador/VistaPanelLateral.java @@ -19,12 +19,13 @@ public class VistaPanelLateral extends JPanel{ //protected JButton elegirMes; protected static DatePicker elegirMes = inicializarCalendario(); protected JButton mostrarEstadisticas; - + JButton aniadirGestion; VistaPanelLateral(GridBagConstraints constrain){ this.setPreferredSize(new Dimension(200,200)); this.total = new JTextArea(); this.gastoEnvio = new JTextArea(); this.mostrarEstadisticas = new JButton("Mostrar grafico del mes"); + this.aniadirGestion = new JButton("Aniadir nueva gestión"); this.add(this.mostrarEstadisticas); constrain.gridx = 1; constrain.gridy = 0;