Iniciando funcionalidad estadisticas
This commit is contained in:
		
							parent
							
								
									da28be150a
								
							
						
					
					
						commit
						8af689363a
					
				| @ -2,5 +2,7 @@ | ||||
| <classpath> | ||||
| 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||||
| 	<classpathentry kind="src" path="src"/> | ||||
| 	<classpathentry kind="lib" path="/home/roche/Descargas/jfreechart-1.5.0-javadoc.jar"/> | ||||
| 	<classpathentry kind="lib" path="/home/roche/Descargas/jfreechart-1.5.0.jar"/> | ||||
| 	<classpathentry kind="output" path="bin"/> | ||||
| </classpath> | ||||
|  | ||||
							
								
								
									
										2
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,3 +1 @@ | ||||
| /VistaControlador/ | ||||
| /PedirDatos/ | ||||
| /Logica/ | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								bin/Logica/Gestion.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/Logica/Gestion.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								bin/Logica/Transaccion.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/Logica/Transaccion.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -9,10 +9,10 @@ import javax.swing.event.ChangeListener; | ||||
| 
 | ||||
| import Logica.Gestion; | ||||
| 
 | ||||
| public class Controlador implements ActionListener,ChangeListener{ | ||||
| public class ControladorAniadirVisualizar implements ActionListener,ChangeListener{ | ||||
| 
 | ||||
| 	private Vista vista; | ||||
| 	public Controlador(Vista vista) { | ||||
| 	private VistaAniadirVisualizar vista; | ||||
| 	public ControladorAniadirVisualizar(VistaAniadirVisualizar vista) { | ||||
| 		this.vista=vista; | ||||
| 		this.aniadirListeners(); | ||||
| 	} | ||||
| @ -34,9 +34,9 @@ public class Controlador implements ActionListener,ChangeListener{ | ||||
| 			 | ||||
| 			try { | ||||
| 				this.vista.aniadirElemento(nombre, Integer.parseInt(dinero),this); | ||||
| 				this.vista.menu.total.setText(String.valueOf(Gestion.getTotal())); | ||||
| 				this.vista.menu.total.revalidate(); | ||||
| 				this.vista.menu.total.repaint(); | ||||
| 				this.vista.menu.panel.actualizarDatos(this.vista.gestiones); | ||||
| 				this.vista.menu.panel.revalidate(); | ||||
| 				this.vista.menu.panel.repaint(); | ||||
| 			}catch (NumberFormatException ex) { | ||||
| 				JOptionPane.showMessageDialog(null, "Debe introducir un numero", "error", JOptionPane.WARNING_MESSAGE); | ||||
| 			} | ||||
| @ -45,9 +45,9 @@ public class Controlador implements ActionListener,ChangeListener{ | ||||
| 			for(int i=0;i<vista.gestiones.getElementos().size();i++) { | ||||
| 				if(vista.gestiones.getElementos().get(i).toString().equals(pulsado.getText())) { | ||||
| 					vista.gestiones.alterarVisibilidad(i); | ||||
| 					this.vista.menu.total.setText(String.valueOf(Gestion.getTotal())); | ||||
| 					this.vista.menu.total.revalidate(); | ||||
| 					this.vista.menu.total.repaint(); | ||||
| 					this.vista.menu.panel.actualizarDatos(this.vista.gestiones); | ||||
| 					this.vista.menu.panel.revalidate(); | ||||
| 					this.vista.menu.panel.repaint(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
							
								
								
									
										29
									
								
								src/VistaControlador/ControladorPanelLateral.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/VistaControlador/ControladorPanelLateral.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| package VistaControlador; | ||||
| 
 | ||||
| import java.awt.event.ActionEvent; | ||||
| import java.awt.event.ActionListener; | ||||
| 
 | ||||
| import org.jfree.chart.ChartFrame; | ||||
| import org.jfree.chart.JFreeChart; | ||||
| import org.jfree.chart.plot.Plot; | ||||
| import org.jfree.chart.plot.XYPlot; | ||||
| public class ControladorPanelLateral implements ActionListener{ | ||||
| 	private VistaPanelLateral vista; | ||||
| 	public void actionPerformed(ActionEvent e) { | ||||
| 		if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { | ||||
| 			 | ||||
| 			XYPlot plot=new XYPlot(); | ||||
| 			 | ||||
| 			JFreeChart chart=new JFreeChart(plot); | ||||
| 			ChartFrame frame=new ChartFrame("Estadisricas", chart); | ||||
| 			frame.setVisible(true); | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	private void aniadirElementos() { | ||||
| 		this.vista.mostrarEstadisticas.addActionListener(this); | ||||
| 		this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas"); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| @ -9,20 +9,27 @@ import javax.swing.JFrame; | ||||
| import javax.swing.JPanel; | ||||
| import javax.swing.JTabbedPane; | ||||
| import javax.swing.JTextArea; | ||||
| import javax.swing.event.ChangeEvent; | ||||
| import javax.swing.event.ChangeListener; | ||||
| 
 | ||||
| import Logica.Gestion; | ||||
| 
 | ||||
| public class Menu extends JFrame{ | ||||
| 	protected JPanel panelCentral; | ||||
| 	protected JTabbedPane pestania; | ||||
| 	protected Vista ingresos; | ||||
| 	protected Vista gastos; | ||||
| 	protected JTextArea total; | ||||
| 	protected VistaAniadirVisualizar ingresos; | ||||
| 	protected VistaAniadirVisualizar gastos; | ||||
| 	protected VistaPanelLateral panel; | ||||
| 	protected Gestion datosGastos; | ||||
| 	protected Gestion datosIngresos; | ||||
| 	public Menu() { | ||||
| 		this.datosGastos=new Gestion(); | ||||
| 		this.datosIngresos=new Gestion(); | ||||
| 		this.setLayout(new GridBagLayout()); | ||||
| 		GridBagConstraints constrain=new GridBagConstraints(); | ||||
| 		this.ingresos=new Vista(this); | ||||
| 		this.gastos=new Vista(this); | ||||
| 		this.panel=new VistaPanelLateral(constrain); | ||||
| 		this.ingresos=new VistaAniadirVisualizar(this,datosIngresos); | ||||
| 		this.gastos=new VistaAniadirVisualizar(this,datosGastos); | ||||
| 		this.panelCentral=new JPanel(); | ||||
| 		this.pestania=new JTabbedPane(); | ||||
| 		constrain.fill=GridBagConstraints.VERTICAL; | ||||
| @ -33,20 +40,28 @@ public class Menu extends JFrame{ | ||||
| 		this.pestania.addTab("Ingresos", ingresos); | ||||
| 		this.pestania.addTab("Gastos", gastos); | ||||
| 		getContentPane().add(pestania); | ||||
| 		//getContentPane().add(boton); | ||||
| 		setTitle("Titulo"); | ||||
| 		setSize(new Dimension(230,320)); | ||||
| 		setDefaultCloseOperation(3); | ||||
| 		setLocationRelativeTo(null); | ||||
| 		Controlador controlador=new Controlador(this.ingresos); | ||||
| 		Controlador controlador2=new Controlador(this.gastos); | ||||
| 		constrain.fill=GridBagConstraints.HORIZONTAL; | ||||
| 		ControladorAniadirVisualizar controlador=new ControladorAniadirVisualizar(this.ingresos); | ||||
| 		ControladorAniadirVisualizar controlador2=new ControladorAniadirVisualizar(this.gastos); | ||||
| 		/*constrain.fill=GridBagConstraints.HORIZONTAL; | ||||
| 		constrain.gridx=1; | ||||
| 		constrain.gridy=0; | ||||
| 		constrain.weightx=1; | ||||
| 		constrain.weighty=2; | ||||
| 		this.total=new JTextArea(String.valueOf(Gestion.getTotal())); | ||||
| 		this.add(this.total,constrain); | ||||
| 		constrain.weighty=2;*/ | ||||
| 		this.panel.actualizarDatos(datosIngresos); | ||||
| 		this.pestania.addChangeListener((ChangeListener)->{ | ||||
| 			if(this.pestania.getSelectedIndex()==0) { | ||||
| 				this.panel.actualizarDatos(datosIngresos); | ||||
| 			}else { | ||||
| 				this.panel.actualizarDatos(datosGastos); | ||||
| 			} | ||||
| 		}); | ||||
| 		this.add(this.panel); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	 | ||||
| } | ||||
|  | ||||
| @ -11,21 +11,23 @@ import javax.swing.JScrollPane; | ||||
| 
 | ||||
| import Logica.*; | ||||
| 
 | ||||
| public class Vista extends JPanel{ | ||||
| public class VistaAniadirVisualizar extends JPanel{ | ||||
| 	private int x,y; | ||||
| 	private static final int altocheck=28; | ||||
| 	private static final int altoCheck=28; | ||||
| 	protected Gestion gestiones; | ||||
| 	protected JButton boton; | ||||
| 	protected LinkedList<JCheckBox> transacciones; | ||||
| 	JPanel cuadro; | ||||
| 	JScrollPane panel; | ||||
| 	Menu menu; | ||||
| 	public Vista(Menu menu) { | ||||
| 	 | ||||
| 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) { | ||||
| 		this.gestiones=gestion; | ||||
| 		this.transacciones=new LinkedList<JCheckBox>(); | ||||
| 		this.menu=menu; | ||||
| 		this.x=100; | ||||
| 		this.boton=new JButton("aniadir"); | ||||
| 		this.gestiones=new Gestion(); | ||||
| 		//this.gestiones=new Gestion(); | ||||
| 		this.add(boton); | ||||
| 		this.cuadro=new JPanel(); | ||||
| 		this.panel=new JScrollPane(cuadro); | ||||
| @ -37,16 +39,16 @@ public class Vista extends JPanel{ | ||||
| 		this.add(panel); | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirElemento(String nombre, int dinero, Controlador controlador) { | ||||
| 	public void aniadirElemento(String nombre, int dinero, ControladorAniadirVisualizar controlador) { | ||||
| 		Transaccion transaccion=new Transaccion(nombre, dinero); | ||||
| 		this.gestiones.aniadirGasto(transaccion); | ||||
| 		JCheckBox check=new JCheckBox(transaccion.toString()); | ||||
| 		check.setSelected(true); | ||||
| 		check.setSize(new Dimension(x,Vista.altocheck)); | ||||
| 		check.setSize(new Dimension(x,VistaAniadirVisualizar.altoCheck)); | ||||
| 		check.addActionListener(controlador); | ||||
| 		this.transacciones.add(check); | ||||
| 		this.cuadro.add(check); | ||||
| 		this.y+=Vista.altocheck; | ||||
| 		this.y+=VistaAniadirVisualizar.altoCheck; | ||||
| 		cuadro.setPreferredSize(new Dimension(x, y)); | ||||
| 		this.revalidate(); | ||||
| 		this.repaint(); | ||||
							
								
								
									
										42
									
								
								src/VistaControlador/VistaPanelLateral.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/VistaControlador/VistaPanelLateral.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | ||||
| package VistaControlador; | ||||
| 
 | ||||
| import java.awt.GridBagConstraints; | ||||
| 
 | ||||
| import javax.swing.JButton; | ||||
| import javax.swing.JPanel; | ||||
| import javax.swing.JTextArea; | ||||
| 
 | ||||
| import Logica.Gestion; | ||||
| 
 | ||||
| public class VistaPanelLateral extends JPanel{ | ||||
| 	protected JTextArea total; | ||||
| 	protected JTextArea gastoEnvio; | ||||
| 	protected JButton elegirMes; | ||||
| 	protected JButton mostrarEstadisticas; | ||||
| 	 | ||||
| 	VistaPanelLateral(GridBagConstraints constrain){ | ||||
| 		this.total=new JTextArea(); | ||||
| 		this.gastoEnvio=new JTextArea(); | ||||
| 		this.elegirMes=new JButton("Elegir mes"); | ||||
| 		this.mostrarEstadisticas=new JButton("Mostrar grafico del mes"); | ||||
| 		this.add(this.mostrarEstadisticas); | ||||
| 		constrain.gridx=1; | ||||
| 		constrain.gridy=0; | ||||
| 		constrain.weightx=2; | ||||
| 		this.add(this.elegirMes); | ||||
| 		constrain.gridx=1; | ||||
| 		constrain.gridy=1; | ||||
| 		constrain.weightx=2; | ||||
| 		this.add(this.total); | ||||
| 		constrain.gridx=1; | ||||
| 		constrain.gridy=2; | ||||
| 		constrain.weightx=2; | ||||
| 		this.add(this.gastoEnvio); | ||||
| 	} | ||||
| 	 | ||||
| 	void actualizarDatos(Gestion gestion) { | ||||
| 		this.total.setText("Total: "+String.valueOf(Gestion.getTotal())+"€"); | ||||
| 		this.gastoEnvio.setText("Suma: "+String.valueOf(gestion.getSuma())+"€"); | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user