Iniciando funcionalidad estadisticas

This commit is contained in:
roche 2019-11-12 13:58:07 +01:00
parent da28be150a
commit 8af689363a
9 changed files with 118 additions and 30 deletions

View File

@ -2,5 +2,7 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <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="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"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

2
bin/.gitignore vendored
View File

@ -1,3 +1 @@
/VistaControlador/ /VistaControlador/
/PedirDatos/
/Logica/

BIN
bin/Logica/Gestion.class Normal file

Binary file not shown.

Binary file not shown.

View File

@ -9,10 +9,10 @@ import javax.swing.event.ChangeListener;
import Logica.Gestion; import Logica.Gestion;
public class Controlador implements ActionListener,ChangeListener{ public class ControladorAniadirVisualizar implements ActionListener,ChangeListener{
private Vista vista; private VistaAniadirVisualizar vista;
public Controlador(Vista vista) { public ControladorAniadirVisualizar(VistaAniadirVisualizar vista) {
this.vista=vista; this.vista=vista;
this.aniadirListeners(); this.aniadirListeners();
} }
@ -34,9 +34,9 @@ public class Controlador implements ActionListener,ChangeListener{
try { try {
this.vista.aniadirElemento(nombre, Integer.parseInt(dinero),this); this.vista.aniadirElemento(nombre, Integer.parseInt(dinero),this);
this.vista.menu.total.setText(String.valueOf(Gestion.getTotal())); this.vista.menu.panel.actualizarDatos(this.vista.gestiones);
this.vista.menu.total.revalidate(); this.vista.menu.panel.revalidate();
this.vista.menu.total.repaint(); this.vista.menu.panel.repaint();
}catch (NumberFormatException ex) { }catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "Debe introducir un numero", "error", JOptionPane.WARNING_MESSAGE); 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++) { for(int i=0;i<vista.gestiones.getElementos().size();i++) {
if(vista.gestiones.getElementos().get(i).toString().equals(pulsado.getText())) { if(vista.gestiones.getElementos().get(i).toString().equals(pulsado.getText())) {
vista.gestiones.alterarVisibilidad(i); vista.gestiones.alterarVisibilidad(i);
this.vista.menu.total.setText(String.valueOf(Gestion.getTotal())); this.vista.menu.panel.actualizarDatos(this.vista.gestiones);
this.vista.menu.total.revalidate(); this.vista.menu.panel.revalidate();
this.vista.menu.total.repaint(); this.vista.menu.panel.repaint();
} }
} }
} }

View 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");
}
}

View File

@ -9,20 +9,27 @@ import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTabbedPane; import javax.swing.JTabbedPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import Logica.Gestion; import Logica.Gestion;
public class Menu extends JFrame{ public class Menu extends JFrame{
protected JPanel panelCentral; protected JPanel panelCentral;
protected JTabbedPane pestania; protected JTabbedPane pestania;
protected Vista ingresos; protected VistaAniadirVisualizar ingresos;
protected Vista gastos; protected VistaAniadirVisualizar gastos;
protected JTextArea total; protected VistaPanelLateral panel;
protected Gestion datosGastos;
protected Gestion datosIngresos;
public Menu() { public Menu() {
this.datosGastos=new Gestion();
this.datosIngresos=new Gestion();
this.setLayout(new GridBagLayout()); this.setLayout(new GridBagLayout());
GridBagConstraints constrain=new GridBagConstraints(); GridBagConstraints constrain=new GridBagConstraints();
this.ingresos=new Vista(this); this.panel=new VistaPanelLateral(constrain);
this.gastos=new Vista(this); this.ingresos=new VistaAniadirVisualizar(this,datosIngresos);
this.gastos=new VistaAniadirVisualizar(this,datosGastos);
this.panelCentral=new JPanel(); this.panelCentral=new JPanel();
this.pestania=new JTabbedPane(); this.pestania=new JTabbedPane();
constrain.fill=GridBagConstraints.VERTICAL; constrain.fill=GridBagConstraints.VERTICAL;
@ -33,20 +40,28 @@ public class Menu extends JFrame{
this.pestania.addTab("Ingresos", ingresos); this.pestania.addTab("Ingresos", ingresos);
this.pestania.addTab("Gastos", gastos); this.pestania.addTab("Gastos", gastos);
getContentPane().add(pestania); getContentPane().add(pestania);
//getContentPane().add(boton);
setTitle("Titulo"); setTitle("Titulo");
setSize(new Dimension(230,320)); setSize(new Dimension(230,320));
setDefaultCloseOperation(3); setDefaultCloseOperation(3);
setLocationRelativeTo(null); setLocationRelativeTo(null);
Controlador controlador=new Controlador(this.ingresos); ControladorAniadirVisualizar controlador=new ControladorAniadirVisualizar(this.ingresos);
Controlador controlador2=new Controlador(this.gastos); ControladorAniadirVisualizar controlador2=new ControladorAniadirVisualizar(this.gastos);
constrain.fill=GridBagConstraints.HORIZONTAL; /*constrain.fill=GridBagConstraints.HORIZONTAL;
constrain.gridx=1; constrain.gridx=1;
constrain.gridy=0; constrain.gridy=0;
constrain.weightx=1; constrain.weightx=1;
constrain.weighty=2; constrain.weighty=2;*/
this.total=new JTextArea(String.valueOf(Gestion.getTotal())); this.panel.actualizarDatos(datosIngresos);
this.add(this.total,constrain); this.pestania.addChangeListener((ChangeListener)->{
if(this.pestania.getSelectedIndex()==0) {
this.panel.actualizarDatos(datosIngresos);
}else {
this.panel.actualizarDatos(datosGastos);
}
});
this.add(this.panel);
} }
} }

View File

@ -11,21 +11,23 @@ import javax.swing.JScrollPane;
import Logica.*; import Logica.*;
public class Vista extends JPanel{ public class VistaAniadirVisualizar extends JPanel{
private int x,y; private int x,y;
private static final int altocheck=28; private static final int altoCheck=28;
protected Gestion gestiones; protected Gestion gestiones;
protected JButton boton; protected JButton boton;
protected LinkedList<JCheckBox> transacciones; protected LinkedList<JCheckBox> transacciones;
JPanel cuadro; JPanel cuadro;
JScrollPane panel; JScrollPane panel;
Menu menu; Menu menu;
public Vista(Menu menu) {
public VistaAniadirVisualizar(Menu menu, Gestion gestion) {
this.gestiones=gestion;
this.transacciones=new LinkedList<JCheckBox>(); this.transacciones=new LinkedList<JCheckBox>();
this.menu=menu; this.menu=menu;
this.x=100; this.x=100;
this.boton=new JButton("aniadir"); this.boton=new JButton("aniadir");
this.gestiones=new Gestion(); //this.gestiones=new Gestion();
this.add(boton); this.add(boton);
this.cuadro=new JPanel(); this.cuadro=new JPanel();
this.panel=new JScrollPane(cuadro); this.panel=new JScrollPane(cuadro);
@ -37,16 +39,16 @@ public class Vista extends JPanel{
this.add(panel); 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); Transaccion transaccion=new Transaccion(nombre, dinero);
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);
check.setSize(new Dimension(x,Vista.altocheck)); check.setSize(new Dimension(x,VistaAniadirVisualizar.altoCheck));
check.addActionListener(controlador); check.addActionListener(controlador);
this.transacciones.add(check); this.transacciones.add(check);
this.cuadro.add(check); this.cuadro.add(check);
this.y+=Vista.altocheck; this.y+=VistaAniadirVisualizar.altoCheck;
cuadro.setPreferredSize(new Dimension(x, y)); cuadro.setPreferredSize(new Dimension(x, y));
this.revalidate(); this.revalidate();
this.repaint(); this.repaint();

View 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())+"");
}
}