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{ | ||||
| 	private Vector<Transaccion> gestiones; | ||||
| 	private float suma; | ||||
| 	private static float total; | ||||
| 	private static float total = 0; | ||||
| 	private Month mes; | ||||
| 	private Year anio; | ||||
| 	private boolean isPositivo; | ||||
| @ -15,7 +15,6 @@ public class Gestion{ | ||||
| 	public Gestion(String nombre, boolean isPositivo) { | ||||
| 		this.gestiones = new Vector<Transaccion>(); | ||||
| 		this.suma = 0; | ||||
| 		Gestion.total = 0; | ||||
| 		this.nombre = nombre; | ||||
| 		this.isPositivo = isPositivo; | ||||
| 	} | ||||
|  | ||||
| @ -56,6 +56,8 @@ private ArrayList<Mes> meses; | ||||
| 			} | ||||
| 		} | ||||
| 		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(){ | ||||
|  | ||||
| @ -107,6 +107,7 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen | ||||
| 		if(this.mes!=VistaPanelLateral.elegirMes.getDate().getMonth() ||  | ||||
| 				this.anio!=VistaPanelLateral.elegirMes.getDate().getYear()) { | ||||
| 			System.out.println("Cambia mes"); | ||||
| 			this.menu.cargarGestiones(VistaPanelLateral.elegirMes.getDate().getYear(), VistaPanelLateral.elegirMes.getDate().getMonth()); | ||||
| 			this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); | ||||
| 			this.anio=VistaPanelLateral.elegirMes.getDate().getYear(); | ||||
| 		} | ||||
|  | ||||
| @ -50,16 +50,15 @@ public class Menu extends JFrame{ | ||||
| 		setLocationRelativeTo(null); | ||||
| 		ControladorPanelLateral controlador3 = new ControladorPanelLateral(this.panel, this); | ||||
| 		this.pestania.addChangeListener((ChangeListener)->{ | ||||
| 			if(this.pestania.getSelectedIndex() == 0) { | ||||
| 				this.panel.actualizarDatos(meses.getGestionesActuales().get(0)); | ||||
| 			}else { | ||||
| 				this.panel.actualizarDatos(meses.getGestionesActuales().get(1)); | ||||
| 			if(this.pestania.getTabCount()<0) { | ||||
| 				this.panel.actualizarDatos(meses.getGestionesActuales().get(this.pestania.getSelectedIndex())); | ||||
| 			} | ||||
| 		}); | ||||
| 		this.add(this.panel); | ||||
| 	} | ||||
| 	 | ||||
| 	private void iniciarMes(int anio, Month mes) { | ||||
| 		this.pestania.removeAll(); | ||||
| 		meses.aniadirGestion("Ingresos", anio, mes, true); | ||||
| 		meses.aniadirGestion("Gastos", anio, mes, false); | ||||
| 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | ||||
| @ -68,28 +67,34 @@ public class Menu extends JFrame{ | ||||
| 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | ||||
| 		this.controladores.add(new ControladorAniadirVisualizar(this.pestanias.get(0))); | ||||
| 		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) { | ||||
| 			this.meses=new Meses(); | ||||
| 		} | ||||
| 		this.meses.elegirMes(anio, mes); | ||||
| 		if(this.meses.getGestionesActuales().size() == 0) { | ||||
| 			this.iniciarMes(anio, mes); | ||||
| 			System.out.println("entra"); | ||||
| 		}else { | ||||
| 			this.cargarMes(); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	private void cargarMes() { | ||||
| 		this.pestanias=new ArrayList<VistaAniadirVisualizar>(); | ||||
| 		this.controladores=new ArrayList<ControladorAniadirVisualizar>(); | ||||
| 		this.pestania.removeAll(); | ||||
| 		this.pestanias.clear(); | ||||
| 		this.controladores.clear(); | ||||
| 		for(Gestion gestion:this.meses.getGestionesActuales()) { | ||||
| 			VistaAniadirVisualizar vista = new VistaAniadirVisualizar(this, gestion); | ||||
| 			this.pestania.add(vista); | ||||
| 			this.controladores.add(new ControladorAniadirVisualizar(vista)); | ||||
| 			ControladorAniadirVisualizar controlador = new ControladorAniadirVisualizar(vista); | ||||
| 			vista.iniciarGestion(); | ||||
| 			this.pestanias.add(vista); | ||||
| 			this.controladores.add(controlador); | ||||
| 		} | ||||
| 		this.cargarPestanias(); | ||||
| 	} | ||||
| 	 | ||||
| 	void cargarPestanias() { | ||||
|  | ||||
| @ -20,6 +20,7 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 	JPanel cuadro; | ||||
| 	JScrollPane panel; | ||||
| 	Menu menu; | ||||
| 	private ControladorAniadirVisualizar controlador; | ||||
| 	static VistaPanelLateral panelLateral; | ||||
| 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) { | ||||
| 		this.gestiones = gestion; | ||||
| @ -46,6 +47,12 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 		return this.gestiones.getNombre(); | ||||
| 	} | ||||
| 	 | ||||
| 	void iniciarGestion() { | ||||
| 		for(Transaccion transaccion:this.gestiones.getElementos()) { | ||||
| 			 this.aniadirElemento(transaccion); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | ||||
| 		Transaccion transaccion = new Transaccion(nombre, dinero,panelLateral.getDate()); | ||||
| 		this.gestiones.aniadirGasto(transaccion); | ||||
| @ -60,4 +67,18 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 		this.revalidate(); | ||||
| 		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