Aniadido soporte para cambiar de mes
This commit is contained in:
		
							parent
							
								
									21203e9524
								
							
						
					
					
						commit
						86c642dba9
					
				
										
											Binary file not shown.
										
									
								
							| @ -6,7 +6,7 @@ import java.util.Vector; | |||||||
| public class Gestion{ | public class Gestion{ | ||||||
| 	private Vector<Transaccion> gestiones; | 	private Vector<Transaccion> gestiones; | ||||||
| 	private float suma; | 	private float suma; | ||||||
| 	private static float total; | 	private static float total = 0; | ||||||
| 	private Month mes; | 	private Month mes; | ||||||
| 	private Year anio; | 	private Year anio; | ||||||
| 	private boolean isPositivo; | 	private boolean isPositivo; | ||||||
| @ -15,7 +15,6 @@ public class Gestion{ | |||||||
| 	public Gestion(String nombre, boolean isPositivo) { | 	public Gestion(String nombre, boolean isPositivo) { | ||||||
| 		this.gestiones = new Vector<Transaccion>(); | 		this.gestiones = new Vector<Transaccion>(); | ||||||
| 		this.suma = 0; | 		this.suma = 0; | ||||||
| 		Gestion.total = 0; |  | ||||||
| 		this.nombre = nombre; | 		this.nombre = nombre; | ||||||
| 		this.isPositivo = isPositivo; | 		this.isPositivo = isPositivo; | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -56,6 +56,8 @@ private ArrayList<Mes> meses; | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		this.meses.add(new Mes(new ArrayList<Gestion>(), anio, mes)); | 		this.meses.add(new Mes(new ArrayList<Gestion>(), anio, mes)); | ||||||
|  | 		this.mesActual = this.meses.size()-1; | ||||||
|  | 		System.out.println(this.meses.size()-1); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public ArrayList<Gestion> getGestionesActuales(){ | 	public ArrayList<Gestion> getGestionesActuales(){ | ||||||
|  | |||||||
| @ -107,6 +107,7 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen | |||||||
| 		if(this.mes!=VistaPanelLateral.elegirMes.getDate().getMonth() ||  | 		if(this.mes!=VistaPanelLateral.elegirMes.getDate().getMonth() ||  | ||||||
| 				this.anio!=VistaPanelLateral.elegirMes.getDate().getYear()) { | 				this.anio!=VistaPanelLateral.elegirMes.getDate().getYear()) { | ||||||
| 			System.out.println("Cambia mes"); | 			System.out.println("Cambia mes"); | ||||||
|  | 			this.menu.cargarGestiones(VistaPanelLateral.elegirMes.getDate().getYear(), VistaPanelLateral.elegirMes.getDate().getMonth()); | ||||||
| 			this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); | 			this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); | ||||||
| 			this.anio=VistaPanelLateral.elegirMes.getDate().getYear(); | 			this.anio=VistaPanelLateral.elegirMes.getDate().getYear(); | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -50,16 +50,15 @@ public class Menu extends JFrame{ | |||||||
| 		setLocationRelativeTo(null); | 		setLocationRelativeTo(null); | ||||||
| 		ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this); | 		ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this); | ||||||
| 		this.pestania.addChangeListener((ChangeListener)->{ | 		this.pestania.addChangeListener((ChangeListener)->{ | ||||||
| 			if(this.pestania.getSelectedIndex() == 0) { | 			if(this.pestania.getTabCount()<0) { | ||||||
| 				this.panel.actualizarDatos(meses.getGestionesActuales().get(0)); | 				this.panel.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex())); | ||||||
| 			}else { |  | ||||||
| 				this.panel.actualizarDatos(meses.getGestionesActuales().get(1)); |  | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 		this.add(this.panel); | 		this.add(this.panel); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private void iniciarMes(int anio, Month mes) { | 	private void iniciarMes(int anio, Month mes) { | ||||||
|  | 		this.pestania.removeAll(); | ||||||
| 		meses.aniadirGestion("Ingresos", anio, mes, true); | 		meses.aniadirGestion("Ingresos", anio, mes, true); | ||||||
| 		meses.aniadirGestion("Gastos", anio, mes, false); | 		meses.aniadirGestion("Gastos", anio, mes, false); | ||||||
| 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | ||||||
| @ -68,28 +67,34 @@ public class Menu extends JFrame{ | |||||||
| 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | ||||||
| 		this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(0))); | 		this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(0))); | ||||||
| 		this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(1))); | 		this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(1))); | ||||||
|  | 		this.cargarPestanias(); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private void cargarGestiones(int anio, Month mes) { | 	void cargarGestiones(int anio, Month mes) { | ||||||
| 		if(this.meses==null) { | 		if(this.meses==null) { | ||||||
| 			this.meses=new Meses(); | 			this.meses=new Meses(); | ||||||
| 		} | 		} | ||||||
| 		this.meses.elegirMes(anio, mes); | 		this.meses.elegirMes(anio, mes); | ||||||
| 		if(this.meses.getGestionesActuales().size() == 0) { | 		if(this.meses.getGestionesActuales().size() == 0) { | ||||||
| 			this.iniciarMes(anio, mes); | 			this.iniciarMes(anio, mes); | ||||||
|  | 			System.out.println("entra"); | ||||||
| 		}else { | 		}else { | ||||||
| 			this.cargarMes(); | 			this.cargarMes(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private void cargarMes() { | 	private void cargarMes() { | ||||||
| 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | 		this.pestania.removeAll(); | ||||||
| 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | 		this.pestanias.clear(); | ||||||
|  | 		this.controladores.clear(); | ||||||
| 		for(Gestion gestion:this.meses.getGestionesActuales()) { | 		for(Gestion gestion:this.meses.getGestionesActuales()) { | ||||||
| 			VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); | 			VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); | ||||||
| 			this.pestania.add(vista); | 			ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(vista); | ||||||
| 			this.controladores.add(new ControladorAniadirVisualizar(vista)); | 			vista.iniciarGestion(); | ||||||
|  | 			this.pestanias.add(vista); | ||||||
|  | 			this.controladores.add(controlador); | ||||||
| 		} | 		} | ||||||
|  | 		this.cargarPestanias(); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	void cargarPestanias() { | 	void cargarPestanias() { | ||||||
|  | |||||||
| @ -20,6 +20,7 @@ public class VistaAniadirVisualizar extends JPanel{ | |||||||
| 	JPanel cuadro; | 	JPanel cuadro; | ||||||
| 	JScrollPane panel; | 	JScrollPane panel; | ||||||
| 	Menu menu; | 	Menu menu; | ||||||
|  | 	private ControladorAniadirVisualizar controlador; | ||||||
| 	static VistaPanelLateral panelLateral; | 	static VistaPanelLateral panelLateral; | ||||||
| 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) { | 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) { | ||||||
| 		this.gestiones = gestion; | 		this.gestiones = gestion; | ||||||
| @ -46,6 +47,12 @@ public class VistaAniadirVisualizar extends JPanel{ | |||||||
| 		return this.gestiones.getNombre(); | 		return this.gestiones.getNombre(); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
|  | 	void iniciarGestion() { | ||||||
|  | 		for(Transaccion transaccion:this.gestiones.getElementos()) { | ||||||
|  | 			 this.aniadirElemento(transaccion); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
| 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | ||||||
| 		Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate()); | 		Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate()); | ||||||
| 		this.gestiones.aniadirGasto(transaccion); | 		this.gestiones.aniadirGasto(transaccion); | ||||||
| @ -60,4 +67,18 @@ public class VistaAniadirVisualizar extends JPanel{ | |||||||
| 		this.revalidate(); | 		this.revalidate(); | ||||||
| 		this.repaint(); | 		this.repaint(); | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	private void aniadirElemento(Transaccion transaccion) { | ||||||
|  | 		JCheckBox check = new JCheckBox(transaccion.toString()); | ||||||
|  | 		check.setSelected(true); | ||||||
|  | 		check.setSize(new Dimension(x,VistaAniadirVisualizar.altoCheck)); | ||||||
|  | 		check.addActionListener(this.boton.getActionListeners()[0]); | ||||||
|  | 		this.transacciones.add(check); | ||||||
|  | 		this.cuadro.add(check); | ||||||
|  | 		this.y += VistaAniadirVisualizar.altoCheck; | ||||||
|  | 		cuadro.setPreferredSize(new Dimension(x, y)); | ||||||
|  | 		this.revalidate(); | ||||||
|  | 		this.repaint(); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user