From ba84d7d15b93aad66e4103b97d698fca320b72a6 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Tue, 12 Nov 2019 21:48:19 +0100 Subject: [PATCH] =?UTF-8?q?Inicio=20soporte=20graficos,=20a=C3=B1adido=20s?= =?UTF-8?q?oporte=20para=20diferenciar=20gastos=20e=20ingresos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/.gitignore | 1 + bin/Logica/Gestion.class | Bin 1401 -> 1579 bytes bin/Logica/Transaccion.class | Bin 1157 -> 1484 bytes src/Logica/Gestion.java | 26 ++++++++++++----- src/Logica/Transaccion.java | 27 ++++++++++++++++-- .../ControladorAniadirVisualizar.java | 2 +- .../ControladorPanelLateral.java | 26 +++++++++++++---- src/VistaControlador/Menu.java | 7 +++-- .../VistaAniadirVisualizar.java | 8 ++++-- src/VistaControlador/VistaPanelLateral.java | 2 ++ 10 files changed, 76 insertions(+), 23 deletions(-) diff --git a/bin/.gitignore b/bin/.gitignore index a1bbed7..dfe691c 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1,2 @@ /VistaControlador/ +/Logica/ diff --git a/bin/Logica/Gestion.class b/bin/Logica/Gestion.class index b2e20509f060b14ff313e02afbe5ffad9d125aa1..84ca809d39d821111a6af1683ce83e6808677f2b 100644 GIT binary patch delta 756 zcmZuuOG_J37(I6qt&U@;8pqJoAR%g;sI9h|+FIiSgf9A!mihu=q7xaK`buz{F1u(K zG7Iq!C?W`2&B8_E+D(5%e?=)2&)kSQkXhWh-}&x$?z!juRgX0F>iI`hI8l*&ZKXu z@Dn~Ll#?{h5KI)&F>B19LFX=(<{|!#Jv5ynB#~bT9UyR1WmuhX)Q3l0BY42|A?nct z9nEM*3*rbOfmRHo4Pkcm%2jyGuKOin^y3Kxp0e;mNvPZppoeRKh}#kT*HD{&?4NY03}- zt~Ab;U5mm+ytqVX5ul|Z delta 562 zcmZutJx>Br5S(`hC{NNnk>Y|ItL#@0eC zP^7RhHa1rF{saGkF){8PqQRJ#YCNJGe2W#^_2xw z8+UAqTQQ9p^@8&x=B${<0)tId%5q68ZR8GfM>!=Yi4p@J3~e!V%8Hzq3*{n1*IHTJ z+g}wA*2SzMt8ZMv$lpQW)g6ANk_8WrOg-T``XdbtWx|_v2-JCZiF5;p-rmAdBNhiI zRT~UcdtgQ{1e%7?2NxkiQwakYq=_^UMg)xBC_+@b35)78U?e}G3SUdpM7XA)=~(sN z_^o5cm|8U0Lsj}|`Zu{wovZE6FiyH0I&{W_dTsD9xB6nRS0)joU(NT4cGkFg?M_z% zQ;+a9Fnf-ees3Gvy8I7F8C)Xz4_#^o)lQd)zO7}(>zTRr?L3s&2!ik;NvEgaM+N~X el+JH{`JepqScHZ4PmqcU+y_!xnn{{CEPVl&dS3tl diff --git a/bin/Logica/Transaccion.class b/bin/Logica/Transaccion.class index 03febd106eaed15353674ade7666c80549e263b8..908129278669a8ba523ade7090adc9db02b4ab7a 100644 GIT binary patch literal 1484 zcmZuw+fGwK6kXF63iXIs+FImNQPH*t^@3OMZipoHl0ceh;=|A$aj>-H^w59s6Z`^S zjL}5EXyOO>QR>>$lX|3mnb~t@*4k_Dz0R-S-+uyF#G^PO3dwSF(^Pe7-P4Vhu2xO6 z5l2j6bW68&sjeHFrDq#kZq-*9Y&5qwJXbLPF4ug|G&YxbTQd#UYbvM}g?QVv%toDW z)k}qF&1goe3PU^1mhnxS&jy!G!}xa;GWlM*l|n@!_OMxV6Nn<|U<702$rmcaP)Iu% zz@S7Y9KV8BX-{{zH(YOBTUD&Os_PZ)894_ZWBwb{ zQb?71Tf+LX{ba7b6rn?Yv(pBG^M&4O;y6dChkN#5*VJpSmp~rHI12x@yhG<;4i}`E zy1wf^d#!LTtf4cOr9Sx*n8kwhti)c0A;GW;l_6Z>Ku*cSD-OMImGjU$J8q+bmcG+WYV7=$fyq zZ=dL$U`oTpJ_@Wx7|oV2t>;}^CDxj|Ue#SOV!qLks~4pIn4vAAwEqAi;vq&6agg2V zAG^~%cBgl^$B7uhF|MOL`Ft<<>EZ#77w7hnDxTd#rWo5pR+f{pOn$NWX?aIH$P=R{ zhsiraM~-pLl5vWRIo_V?Fmj*aNid>J*+{fStb)^lf_GLqkn5))E!m4x)Nxosk`l%! zA;sirMj4Fb1XE?Lghi$#WmiJ3Dmy5QSg z@GILnAYBynd&Hw35VL~{$f8zBg3rK8Mp=uDqoXDr5Z>XJ6e4BX;15G3c8G8hU3YPh jtJor}GxLcb!bQ%9X#eTF-_;ogPaZDvQeW@`o8sYL&2szX literal 1157 zcmZuw+fEZv6kTW9GNlYqS_)nYf){LyQ17=IAJiC0syslNXyU`^bgT!588S@y7r($4 zA2hLGH1PxcD0Q9b2m|HiTxRce+57DI{pZIo0JqUFVF(nOeplJDz8OewSK7AnJrikx z{FdC4bys@b`g(iIu|t6o&);qbj>a4XH^M-9-3Fr_bAl3xTJ+-UaE_1~jh8`(T zg^vYhD#OUNYD*yf)bBVsq%dh=40(Z6rP>+=r7UDHqEFKnOl0+G#=R6Euz-su z7LT=SKxg3+F6%}}x96tK4@v<6ulhgu%w%CRiKoF#Eq`DvZ%7H3p#Px!Zob0 z!E$HE@j3!4ry+)lirqIfMO{-|7bsWOhTS9+Z(2ByvcN>w30r*KJ>{y7q$Zz=Z(NXW z=mau278>6OrTyWh+=-uJl-OtSm=MN6$!++(z;>Q1JuCUd5U%Q$W0B9D;5Ay2l?^Jf53$}0X6xAePt3ipeZ$muTsXj$LS-K{UW@x!-N%hD z%rKypN22V>NJ)DpGFB3}#eZ^8MV-5jWk^x_d;(ldfHQ~SJBQ%6kwu`S4U|5@OnpLH z*Z-d^6*sMi}rO7_qpnBCw&%A`Yb1Ck9 gestiones; - private int suma; - private static int total; + private float suma; + private static float total; public Gestion() { this.gestiones=new Vector(); @@ -15,14 +15,18 @@ public class Gestion{ public void aniadirGasto(Transaccion transaccion) { this.gestiones.add(transaccion); 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; } - public static int getTotal() { + public static float getTotal() { return Gestion.total; } @@ -33,10 +37,18 @@ public class Gestion{ public void alterarVisibilidad(int elemento) { if(this.gestiones.get(elemento).alterarVisivilidad()) { 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 { 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(); + } } } diff --git a/src/Logica/Transaccion.java b/src/Logica/Transaccion.java index 59469e0..a40c8f8 100644 --- a/src/Logica/Transaccion.java +++ b/src/Logica/Transaccion.java @@ -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; + } } diff --git a/src/VistaControlador/ControladorAniadirVisualizar.java b/src/VistaControlador/ControladorAniadirVisualizar.java index 42c3afb..325b857 100644 --- a/src/VistaControlador/ControladorAniadirVisualizar.java +++ b/src/VistaControlador/ControladorAniadirVisualizar.java @@ -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(); diff --git a/src/VistaControlador/ControladorPanelLateral.java b/src/VistaControlador/ControladorPanelLateral.java index 03de1e6..e55d6f6 100644 --- a/src/VistaControlador/ControladorPanelLateral.java +++ b/src/VistaControlador/ControladorPanelLateral.java @@ -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"); } } diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index 90b17cd..a20baeb 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -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; diff --git a/src/VistaControlador/VistaAniadirVisualizar.java b/src/VistaControlador/VistaAniadirVisualizar.java index b3b54c3..5ab4343 100644 --- a/src/VistaControlador/VistaAniadirVisualizar.java +++ b/src/VistaControlador/VistaAniadirVisualizar.java @@ -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(); 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); diff --git a/src/VistaControlador/VistaPanelLateral.java b/src/VistaControlador/VistaPanelLateral.java index da35911..4fcf7b4 100644 --- a/src/VistaControlador/VistaPanelLateral.java +++ b/src/VistaControlador/VistaPanelLateral.java @@ -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");