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/ | ||||
| /Logica/ | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -3,8 +3,8 @@ import java.util.Vector; | ||||
| 
 | ||||
| public class Gestion{ | ||||
| 	private Vector<Transaccion> gestiones; | ||||
| 	private int suma; | ||||
| 	private static int total; | ||||
| 	private float suma; | ||||
| 	private static float total; | ||||
| 	 | ||||
| 	public Gestion() { | ||||
| 		this.gestiones=new Vector<Transaccion>(); | ||||
| @ -15,14 +15,18 @@ public class Gestion{ | ||||
| 	public void aniadirGasto(Transaccion transaccion) { | ||||
| 		this.gestiones.add(transaccion); | ||||
| 		this.suma+=transaccion.getDinero(); | ||||
| 		if(transaccion.isPositivo()) { | ||||
| 			Gestion.total+=transaccion.getDinero(); | ||||
| 		}else { | ||||
| 			Gestion.total-=transaccion.getDinero(); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public int getSuma() { | ||||
| 	public float getSuma() { | ||||
| 		return this.suma; | ||||
| 	} | ||||
| 	 | ||||
| 	public static int getTotal() { | ||||
| 	public static float getTotal() { | ||||
| 		return Gestion.total; | ||||
| 	} | ||||
| 	 | ||||
| @ -33,11 +37,19 @@ public class Gestion{ | ||||
| 	public void alterarVisibilidad(int elemento) { | ||||
| 		if(this.gestiones.get(elemento).alterarVisivilidad()) { | ||||
| 			this.suma+=this.gestiones.get(elemento).getDinero(); | ||||
| 			if(this.gestiones.get(elemento).isPositivo()) { | ||||
| 				Gestion.total+=this.gestiones.get(elemento).getDinero(); | ||||
| 			}else { | ||||
| 			this.suma-=this.gestiones.get(elemento).getDinero(); | ||||
| 				Gestion.total-=this.gestiones.get(elemento).getDinero(); | ||||
| 			} | ||||
| 		}else { | ||||
| 			this.suma-=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 { | ||||
| 	private String nombre; | ||||
| 	private int dinero; | ||||
| 	private float dinero; | ||||
| 	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.dinero=dinero; | ||||
| 		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() { | ||||
| @ -24,7 +36,16 @@ public class Transaccion { | ||||
| 		return this.visible; | ||||
| 	} | ||||
| 	 | ||||
| 	public int getDinero() { | ||||
| 	public float getDinero() { | ||||
| 		/*if(positivo) { | ||||
| 			return this.dinero; | ||||
| 		}else { | ||||
| 			return -this.dinero; | ||||
| 		}*/ | ||||
| 		return this.dinero; | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean isPositivo() { | ||||
| 		return this.positivo; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -33,7 +33,7 @@ public class ControladorAniadirVisualizar implements ActionListener,ChangeListen | ||||
| 			} | ||||
| 			 | ||||
| 			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.revalidate(); | ||||
| 				this.vista.menu.panel.repaint(); | ||||
|  | ||||
| @ -2,21 +2,33 @@ package VistaControlador; | ||||
| 
 | ||||
| import java.awt.event.ActionEvent; | ||||
| import java.awt.event.ActionListener; | ||||
| 
 | ||||
| import org.jfree.chart.ChartFactory; | ||||
| import org.jfree.chart.ChartFrame; | ||||
| import org.jfree.chart.JFreeChart; | ||||
| import org.jfree.chart.plot.Plot; | ||||
| import org.jfree.chart.plot.XYPlot; | ||||
| import org.jfree.data.xy.XYSeries; | ||||
| import org.jfree.data.xy.XYSeriesCollection; | ||||
| public class ControladorPanelLateral implements ActionListener{ | ||||
| 	private VistaPanelLateral vista; | ||||
| 	 | ||||
| 	public ControladorPanelLateral(VistaPanelLateral vista) { | ||||
| 		this.vista=vista; | ||||
| 		this.aniadirElementos(); | ||||
| 	} | ||||
| 	 | ||||
| 	public void actionPerformed(ActionEvent e) { | ||||
| 		if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { | ||||
| 			 | ||||
| 			XYPlot plot=new XYPlot(); | ||||
| 			 | ||||
| 			JFreeChart chart=new JFreeChart(plot); | ||||
| 			XYSeries serie=new XYSeries("Mes"); | ||||
| 			serie.add(10,1); | ||||
| 			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); | ||||
| 			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() { | ||||
| 		this.vista.mostrarEstadisticas.addActionListener(this); | ||||
| 		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()); | ||||
| 		GridBagConstraints constrain=new GridBagConstraints(); | ||||
| 		this.panel=new VistaPanelLateral(constrain); | ||||
| 		this.ingresos=new VistaAniadirVisualizar(this,datosIngresos); | ||||
| 		this.gastos=new VistaAniadirVisualizar(this,datosGastos); | ||||
| 		this.ingresos=new VistaAniadirVisualizar(this,datosIngresos,true); | ||||
| 		this.gastos=new VistaAniadirVisualizar(this,datosGastos,false); | ||||
| 		this.panelCentral=new JPanel(); | ||||
| 		this.pestania=new JTabbedPane(); | ||||
| 		constrain.fill=GridBagConstraints.VERTICAL; | ||||
| @ -41,11 +41,12 @@ public class Menu extends JFrame{ | ||||
| 		this.pestania.addTab("Gastos", gastos); | ||||
| 		getContentPane().add(pestania); | ||||
| 		setTitle("Titulo"); | ||||
| 		setSize(new Dimension(230,320)); | ||||
| 		setSize(new Dimension(420,320)); | ||||
| 		setDefaultCloseOperation(3); | ||||
| 		setLocationRelativeTo(null); | ||||
| 		ControladorAniadirVisualizar controlador=new ControladorAniadirVisualizar(this.ingresos); | ||||
| 		ControladorAniadirVisualizar controlador2=new ControladorAniadirVisualizar(this.gastos); | ||||
| 		ControladorPanelLateral controlador3=new ControladorPanelLateral(this.panel); | ||||
| 		/*constrain.fill=GridBagConstraints.HORIZONTAL; | ||||
| 		constrain.gridx=1; | ||||
| 		constrain.gridy=0; | ||||
|  | ||||
| @ -20,8 +20,10 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 	JPanel cuadro; | ||||
| 	JScrollPane panel; | ||||
| 	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.transacciones=new LinkedList<JCheckBox>(); | ||||
| 		this.menu=menu; | ||||
| @ -39,8 +41,8 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 		this.add(panel); | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirElemento(String nombre, int dinero, ControladorAniadirVisualizar controlador) { | ||||
| 		Transaccion transaccion=new Transaccion(nombre, dinero); | ||||
| 	public void aniadirElemento(String nombre, float dinero, ControladorAniadirVisualizar controlador) { | ||||
| 		Transaccion transaccion=new Transaccion(nombre, dinero,1,this.positivo); | ||||
| 		this.gestiones.aniadirGasto(transaccion); | ||||
| 		JCheckBox check=new JCheckBox(transaccion.toString()); | ||||
| 		check.setSelected(true); | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| package VistaControlador; | ||||
| 
 | ||||
| import java.awt.Dimension; | ||||
| import java.awt.GridBagConstraints; | ||||
| 
 | ||||
| import javax.swing.JButton; | ||||
| @ -15,6 +16,7 @@ public class VistaPanelLateral extends JPanel{ | ||||
| 	protected JButton mostrarEstadisticas; | ||||
| 	 | ||||
| 	VistaPanelLateral(GridBagConstraints constrain){ | ||||
| 		this.setPreferredSize(new Dimension(200,200)); | ||||
| 		this.total=new JTextArea(); | ||||
| 		this.gastoEnvio=new JTextArea(); | ||||
| 		this.elegirMes=new JButton("Elegir mes"); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user