Inicio soporte graficos, añadido soporte para diferenciar gastos e
ingresos
This commit is contained in:
		
							parent
							
								
									8af689363a
								
							
						
					
					
						commit
						ba84d7d15b
					
				
							
								
								
									
										1
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1 +1,2 @@ | |||||||
| /VistaControlador/ | /VistaControlador/ | ||||||
|  | /Logica/ | ||||||
|  | |||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -3,8 +3,8 @@ import java.util.Vector; | |||||||
| 
 | 
 | ||||||
| public class Gestion{ | public class Gestion{ | ||||||
| 	private Vector<Transaccion> gestiones; | 	private Vector<Transaccion> gestiones; | ||||||
| 	private int suma; | 	private float suma; | ||||||
| 	private static int total; | 	private static float total; | ||||||
| 	 | 	 | ||||||
| 	public Gestion() { | 	public Gestion() { | ||||||
| 		this.gestiones=new Vector<Transaccion>(); | 		this.gestiones=new Vector<Transaccion>(); | ||||||
| @ -15,14 +15,18 @@ public class Gestion{ | |||||||
| 	public void aniadirGasto(Transaccion transaccion) { | 	public void aniadirGasto(Transaccion transaccion) { | ||||||
| 		this.gestiones.add(transaccion); | 		this.gestiones.add(transaccion); | ||||||
| 		this.suma+=transaccion.getDinero(); | 		this.suma+=transaccion.getDinero(); | ||||||
| 		Gestion.total+=transaccion.getDinero(); | 		if(transaccion.isPositivo()) { | ||||||
|  | 			Gestion.total+=transaccion.getDinero(); | ||||||
|  | 		}else { | ||||||
|  | 			Gestion.total-=transaccion.getDinero(); | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public int getSuma() { | 	public float getSuma() { | ||||||
| 		return this.suma; | 		return this.suma; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public static int getTotal() { | 	public static float getTotal() { | ||||||
| 		return Gestion.total; | 		return Gestion.total; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| @ -33,10 +37,18 @@ public class Gestion{ | |||||||
| 	public void alterarVisibilidad(int elemento) { | 	public void alterarVisibilidad(int elemento) { | ||||||
| 		if(this.gestiones.get(elemento).alterarVisivilidad()) { | 		if(this.gestiones.get(elemento).alterarVisivilidad()) { | ||||||
| 			this.suma+=this.gestiones.get(elemento).getDinero(); | 			this.suma+=this.gestiones.get(elemento).getDinero(); | ||||||
| 			Gestion.total+=this.gestiones.get(elemento).getDinero(); | 			if(this.gestiones.get(elemento).isPositivo()) { | ||||||
|  | 				Gestion.total+=this.gestiones.get(elemento).getDinero(); | ||||||
|  | 			}else { | ||||||
|  | 				Gestion.total-=this.gestiones.get(elemento).getDinero(); | ||||||
|  | 			} | ||||||
| 		}else { | 		}else { | ||||||
| 			this.suma-=this.gestiones.get(elemento).getDinero(); | 			this.suma-=this.gestiones.get(elemento).getDinero(); | ||||||
| 			Gestion.total-=this.gestiones.get(elemento).getDinero(); | 			if(this.gestiones.get(elemento).isPositivo()) { | ||||||
|  | 				Gestion.total-=this.gestiones.get(elemento).getDinero(); | ||||||
|  | 			}else { | ||||||
|  | 				Gestion.total+=this.gestiones.get(elemento).getDinero(); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,13 +2,25 @@ package Logica; | |||||||
| 
 | 
 | ||||||
| public class Transaccion { | public class Transaccion { | ||||||
| 	private String nombre; | 	private String nombre; | ||||||
| 	private int dinero; | 	private float dinero; | ||||||
| 	private boolean visible; | 	private boolean visible; | ||||||
|  | 	private int dia; | ||||||
|  | 	private boolean positivo; | ||||||
| 	 | 	 | ||||||
| 	public Transaccion(String nombre, int dinero){ | 	public Transaccion(String nombre, float dinero){ | ||||||
| 		this.nombre=nombre; | 		this.nombre=nombre; | ||||||
| 		this.dinero=dinero; | 		this.dinero=dinero; | ||||||
| 		this.visible=true; | 		this.visible=true; | ||||||
|  | 		this.dia=1; | ||||||
|  | 		this.positivo=true; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public Transaccion(String nombre, float dinero, int dia, boolean positivo){ | ||||||
|  | 		this.nombre=nombre; | ||||||
|  | 		this.dinero=dinero; | ||||||
|  | 		this.visible=true; | ||||||
|  | 		this.positivo=positivo; | ||||||
|  | 		this.dia=dia; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public String toString() { | 	public String toString() { | ||||||
| @ -24,7 +36,16 @@ public class Transaccion { | |||||||
| 		return this.visible; | 		return this.visible; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public int getDinero() { | 	public float getDinero() { | ||||||
|  | 		/*if(positivo) { | ||||||
|  | 			return this.dinero; | ||||||
|  | 		}else { | ||||||
|  | 			return -this.dinero; | ||||||
|  | 		}*/ | ||||||
| 		return this.dinero; | 		return this.dinero; | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
|  | 	public boolean isPositivo() { | ||||||
|  | 		return this.positivo; | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ public class ControladorAniadirVisualizar implements ActionListener,ChangeListen | |||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 			try { | 			try { | ||||||
| 				this.vista.aniadirElemento(nombre, Integer.parseInt(dinero),this); | 				this.vista.aniadirElemento(nombre, Float.parseFloat(dinero),this); | ||||||
| 				this.vista.menu.panel.actualizarDatos(this.vista.gestiones); | 				this.vista.menu.panel.actualizarDatos(this.vista.gestiones); | ||||||
| 				this.vista.menu.panel.revalidate(); | 				this.vista.menu.panel.revalidate(); | ||||||
| 				this.vista.menu.panel.repaint(); | 				this.vista.menu.panel.repaint(); | ||||||
|  | |||||||
| @ -2,21 +2,33 @@ package VistaControlador; | |||||||
| 
 | 
 | ||||||
| import java.awt.event.ActionEvent; | import java.awt.event.ActionEvent; | ||||||
| import java.awt.event.ActionListener; | import java.awt.event.ActionListener; | ||||||
| 
 | import org.jfree.chart.ChartFactory; | ||||||
| import org.jfree.chart.ChartFrame; | import org.jfree.chart.ChartFrame; | ||||||
| import org.jfree.chart.JFreeChart; | import org.jfree.chart.JFreeChart; | ||||||
| import org.jfree.chart.plot.Plot; | import org.jfree.data.xy.XYSeries; | ||||||
| import org.jfree.chart.plot.XYPlot; | import org.jfree.data.xy.XYSeriesCollection; | ||||||
| public class ControladorPanelLateral implements ActionListener{ | public class ControladorPanelLateral implements ActionListener{ | ||||||
| 	private VistaPanelLateral vista; | 	private VistaPanelLateral vista; | ||||||
|  | 	 | ||||||
|  | 	public ControladorPanelLateral(VistaPanelLateral vista) { | ||||||
|  | 		this.vista=vista; | ||||||
|  | 		this.aniadirElementos(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
| 	public void actionPerformed(ActionEvent e) { | 	public void actionPerformed(ActionEvent e) { | ||||||
| 		if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { | 		if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { | ||||||
| 			 | 			 | ||||||
| 			XYPlot plot=new XYPlot(); | 			XYSeries serie=new XYSeries("Mes"); | ||||||
| 			 | 			serie.add(10,1); | ||||||
| 			JFreeChart chart=new JFreeChart(plot); | 			serie.add(4,2); | ||||||
|  | 			serie.add(90,10); | ||||||
|  | 			XYSeriesCollection dataset=new XYSeriesCollection(serie); | ||||||
|  | 			JFreeChart chart=ChartFactory.createXYLineChart("Mes", "Dias", "Gastos", dataset); | ||||||
| 			ChartFrame frame=new ChartFrame("Estadisricas", chart); | 			ChartFrame frame=new ChartFrame("Estadisricas", chart); | ||||||
| 			frame.setVisible(true); | 			frame.setVisible(true); | ||||||
|  | 			frame.setSize(700,500); | ||||||
|  | 		}else if(e.getActionCommand().equals(this.vista.elegirMes.getActionCommand())){ | ||||||
|  | 			 | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
| @ -24,6 +36,8 @@ public class ControladorPanelLateral implements ActionListener{ | |||||||
| 	private void aniadirElementos() { | 	private void aniadirElementos() { | ||||||
| 		this.vista.mostrarEstadisticas.addActionListener(this); | 		this.vista.mostrarEstadisticas.addActionListener(this); | ||||||
| 		this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas"); | 		this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas"); | ||||||
|  | 		this.vista.elegirMes.addActionListener(this); | ||||||
|  | 		this.vista.elegirMes.setActionCommand("Elegir mes"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -28,8 +28,8 @@ public class Menu extends JFrame{ | |||||||
| 		this.setLayout(new GridBagLayout()); | 		this.setLayout(new GridBagLayout()); | ||||||
| 		GridBagConstraints constrain=new GridBagConstraints(); | 		GridBagConstraints constrain=new GridBagConstraints(); | ||||||
| 		this.panel=new VistaPanelLateral(constrain); | 		this.panel=new VistaPanelLateral(constrain); | ||||||
| 		this.ingresos=new VistaAniadirVisualizar(this,datosIngresos); | 		this.ingresos=new VistaAniadirVisualizar(this,datosIngresos,true); | ||||||
| 		this.gastos=new VistaAniadirVisualizar(this,datosGastos); | 		this.gastos=new VistaAniadirVisualizar(this,datosGastos,false); | ||||||
| 		this.panelCentral=new JPanel(); | 		this.panelCentral=new JPanel(); | ||||||
| 		this.pestania=new JTabbedPane(); | 		this.pestania=new JTabbedPane(); | ||||||
| 		constrain.fill=GridBagConstraints.VERTICAL; | 		constrain.fill=GridBagConstraints.VERTICAL; | ||||||
| @ -41,11 +41,12 @@ public class Menu extends JFrame{ | |||||||
| 		this.pestania.addTab("Gastos", gastos); | 		this.pestania.addTab("Gastos", gastos); | ||||||
| 		getContentPane().add(pestania); | 		getContentPane().add(pestania); | ||||||
| 		setTitle("Titulo"); | 		setTitle("Titulo"); | ||||||
| 		setSize(new Dimension(230,320)); | 		setSize(new Dimension(420,320)); | ||||||
| 		setDefaultCloseOperation(3); | 		setDefaultCloseOperation(3); | ||||||
| 		setLocationRelativeTo(null); | 		setLocationRelativeTo(null); | ||||||
| 		ControladorAniadirVisualizar controlador=new ControladorAniadirVisualizar(this.ingresos); | 		ControladorAniadirVisualizar controlador=new ControladorAniadirVisualizar(this.ingresos); | ||||||
| 		ControladorAniadirVisualizar controlador2=new ControladorAniadirVisualizar(this.gastos); | 		ControladorAniadirVisualizar controlador2=new ControladorAniadirVisualizar(this.gastos); | ||||||
|  | 		ControladorPanelLateral controlador3=new ControladorPanelLateral(this.panel); | ||||||
| 		/*constrain.fill=GridBagConstraints.HORIZONTAL; | 		/*constrain.fill=GridBagConstraints.HORIZONTAL; | ||||||
| 		constrain.gridx=1; | 		constrain.gridx=1; | ||||||
| 		constrain.gridy=0; | 		constrain.gridy=0; | ||||||
|  | |||||||
| @ -20,8 +20,10 @@ public class VistaAniadirVisualizar extends JPanel{ | |||||||
| 	JPanel cuadro; | 	JPanel cuadro; | ||||||
| 	JScrollPane panel; | 	JScrollPane panel; | ||||||
| 	Menu menu; | 	Menu menu; | ||||||
|  | 	boolean positivo; | ||||||
| 	 | 	 | ||||||
| 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) { | 	public VistaAniadirVisualizar(Menu menu, Gestion gestion,boolean positivo) { | ||||||
|  | 		this.positivo=positivo; | ||||||
| 		this.gestiones=gestion; | 		this.gestiones=gestion; | ||||||
| 		this.transacciones=new LinkedList<JCheckBox>(); | 		this.transacciones=new LinkedList<JCheckBox>(); | ||||||
| 		this.menu=menu; | 		this.menu=menu; | ||||||
| @ -39,8 +41,8 @@ public class VistaAniadirVisualizar extends JPanel{ | |||||||
| 		this.add(panel); | 		this.add(panel); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void aniadirElemento(String nombre, int dinero, ControladorAniadirVisualizar controlador) { | 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | ||||||
| 		Transaccion transaccion=new Transaccion(nombre, dinero); | 		Transaccion transaccion=new Transaccion(nombre, dinero,1,this.positivo); | ||||||
| 		this.gestiones.aniadirGasto(transaccion); | 		this.gestiones.aniadirGasto(transaccion); | ||||||
| 		JCheckBox check=new JCheckBox(transaccion.toString()); | 		JCheckBox check=new JCheckBox(transaccion.toString()); | ||||||
| 		check.setSelected(true); | 		check.setSelected(true); | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| package VistaControlador; | package VistaControlador; | ||||||
| 
 | 
 | ||||||
|  | import java.awt.Dimension; | ||||||
| import java.awt.GridBagConstraints; | import java.awt.GridBagConstraints; | ||||||
| 
 | 
 | ||||||
| import javax.swing.JButton; | import javax.swing.JButton; | ||||||
| @ -15,6 +16,7 @@ public class VistaPanelLateral extends JPanel{ | |||||||
| 	protected JButton mostrarEstadisticas; | 	protected JButton mostrarEstadisticas; | ||||||
| 	 | 	 | ||||||
| 	VistaPanelLateral(GridBagConstraints constrain){ | 	VistaPanelLateral(GridBagConstraints constrain){ | ||||||
|  | 		this.setPreferredSize(new Dimension(200,200)); | ||||||
| 		this.total=new JTextArea(); | 		this.total=new JTextArea(); | ||||||
| 		this.gastoEnvio=new JTextArea(); | 		this.gastoEnvio=new JTextArea(); | ||||||
| 		this.elegirMes=new JButton("Elegir mes"); | 		this.elegirMes=new JButton("Elegir mes"); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user