Terminado soporte aniadir gestion nueva

This commit is contained in:
2019-11-14 20:18:05 +01:00
parent cbace53701
commit 0d7df06ad6
8 changed files with 107 additions and 34 deletions

View File

@@ -7,6 +7,7 @@ import java.awt.event.ActionListener;
import java.time.Year;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
@@ -19,19 +20,63 @@ import com.github.lgooddatepicker.components.DatePicker;
import com.github.lgooddatepicker.optionalusertools.DateChangeListener;
import com.github.lgooddatepicker.zinternaltools.DateChangeEvent;
import com.github.lgooddatepicker.zinternaltools.DemoPanel;
import Logica.Gestion;
public class ControladorPanelLateral implements ActionListener, DateChangeListener{
private VistaPanelLateral vista;
private java.time.Month mes;
private int anio;
private Menu menu;
public ControladorPanelLateral(VistaPanelLateral vista) {
public ControladorPanelLateral(VistaPanelLateral vista, Menu menu) {
this.vista = vista;
this.menu = menu;
this.aniadirElementos();
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) {
switch(e.getActionCommand()) {
case "Mostrar estadisticas":{
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);
break;
}
case "Aniadir una nueva gestion":{
String nombre = JOptionPane.showInputDialog("Introduce un nuevo gasto o ingreso");
if(nombre == null) return;
if(nombre.equals("")) {
JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE);
return;
}
String sumaOResta = JOptionPane.showInputDialog("Son gastos?");
if(sumaOResta == null) return;
if(sumaOResta.equals("")) {
JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE);
return;
}
VistaAniadirVisualizar vistaA;
if(sumaOResta.equalsIgnoreCase("si")) {
this.menu.aniadirGestion(nombre, false);
}else if(sumaOResta.equalsIgnoreCase("no")) {
this.menu.aniadirGestion(nombre, true);
}else {
JOptionPane.showMessageDialog(null, "Debe introducir si o no", "error", JOptionPane.WARNING_MESSAGE);
return;
}
break;
}
}
/*if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) {
XYSeries serie = new XYSeries("Mes");
serie.add(10,1);
@@ -43,12 +88,14 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen
frame.setVisible(true);
frame.setSize(700,500);
}
*/
}
private void aniadirElementos() {
this.vista.mostrarEstadisticas.addActionListener(this);
this.vista.mostrarEstadisticas.setActionCommand("Mostrar estadisticas");
this.vista.aniadirGestion.addActionListener(this);
this.vista.aniadirGestion.setActionCommand("Aniadir una nueva gestion");
if(VistaPanelLateral.elegirMes.getDateChangeListeners().size() == 0) {
VistaPanelLateral.elegirMes.addDateChangeListener(this);
this.mes=VistaPanelLateral.elegirMes.getDate().getMonth();