Corregir bugs y aniadir la opcion de eliminar transacciones
This commit is contained in:
		
							parent
							
								
									86c642dba9
								
							
						
					
					
						commit
						0d6d20001f
					
				
										
											Binary file not shown.
										
									
								
							| @ -6,7 +6,7 @@ import java.util.Vector; | ||||
| public class Gestion{ | ||||
| 	private Vector<Transaccion> gestiones; | ||||
| 	private float suma; | ||||
| 	private static float total = 0; | ||||
| 	private  float total; | ||||
| 	private Month mes; | ||||
| 	private Year anio; | ||||
| 	private boolean isPositivo; | ||||
| @ -15,6 +15,7 @@ public class Gestion{ | ||||
| 	public Gestion(String nombre, boolean isPositivo) { | ||||
| 		this.gestiones = new Vector<Transaccion>(); | ||||
| 		this.suma = 0; | ||||
| 		this.total = 0; | ||||
| 		this.nombre = nombre; | ||||
| 		this.isPositivo = isPositivo; | ||||
| 	} | ||||
| @ -27,9 +28,9 @@ public class Gestion{ | ||||
| 		this.gestiones.add(transaccion); | ||||
| 		this.suma += transaccion.getDinero(); | ||||
| 		if(this.isPositivo) { | ||||
| 			Gestion.total += transaccion.getDinero(); | ||||
| 			this.total += transaccion.getDinero(); | ||||
| 		}else { | ||||
| 			Gestion.total -= transaccion.getDinero(); | ||||
| 			this.total -= transaccion.getDinero(); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| @ -37,28 +38,37 @@ public class Gestion{ | ||||
| 		return this.suma; | ||||
| 	} | ||||
| 	 | ||||
| 	public static float getTotal() { | ||||
| 		return Gestion.total; | ||||
| 	public float getTotal() { | ||||
| 		return this.total; | ||||
| 	} | ||||
| 	 | ||||
| 	public Vector<Transaccion> getElementos(){ | ||||
| 		return this.gestiones; | ||||
| 	} | ||||
| 	 | ||||
| 	public void eliminarTransaccion(String transaccion) { | ||||
| 		for(Transaccion elemento:this.gestiones) { | ||||
| 			if(elemento.toString().equals(transaccion)) { | ||||
| 				this.gestiones.remove(elemento); | ||||
| 				return; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public void alterarVisibilidad(int elemento) { | ||||
| 		if(this.gestiones.get(elemento).alterarVisivilidad()) { | ||||
| 			this.suma += this.gestiones.get(elemento).getDinero(); | ||||
| 			if(this.isPositivo) { | ||||
| 				Gestion.total += this.gestiones.get(elemento).getDinero(); | ||||
| 				this.total += this.gestiones.get(elemento).getDinero(); | ||||
| 			}else { | ||||
| 				Gestion.total -= this.gestiones.get(elemento).getDinero(); | ||||
| 				this.total -= this.gestiones.get(elemento).getDinero(); | ||||
| 			} | ||||
| 		}else { | ||||
| 			this.suma -= this.gestiones.get(elemento).getDinero(); | ||||
| 			if(this.isPositivo) { | ||||
| 				Gestion.total -= this.gestiones.get(elemento).getDinero(); | ||||
| 				this.total -= this.gestiones.get(elemento).getDinero(); | ||||
| 			}else { | ||||
| 				Gestion.total += this.gestiones.get(elemento).getDinero(); | ||||
| 				this.total += this.gestiones.get(elemento).getDinero(); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @ -6,7 +6,6 @@ import java.util.ArrayList; | ||||
| public class Meses { | ||||
| private ArrayList<Mes> meses; | ||||
| 	private int mesActual=0; | ||||
| 	 | ||||
| 	public Meses() { | ||||
| 		this.meses = new ArrayList<Mes>(); | ||||
| 	} | ||||
| @ -57,19 +56,21 @@ private ArrayList<Mes> meses; | ||||
| 		} | ||||
| 		this.meses.add(new Mes(new ArrayList<Gestion>(), anio, mes)); | ||||
| 		this.mesActual = this.meses.size()-1; | ||||
| 		System.out.println(this.meses.size()-1); | ||||
| 	} | ||||
| 	 | ||||
| 	public ArrayList<Gestion> getGestionesActuales(){ | ||||
| 		return this.meses.get(this.mesActual).getGestiones(); | ||||
| 	} | ||||
| 	 | ||||
| 	public float getTotal() { | ||||
| 		return this.meses.get(this.mesActual).getTotal(); | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
| 
 | ||||
| class Mes{ | ||||
| 	private int anio; | ||||
| 	private Month mes; | ||||
| 	int total; | ||||
| 	ArrayList<Gestion> gestiones; | ||||
| 	Mes(ArrayList<Gestion> gestiones, int anio, Month mes){ | ||||
| 		this.gestiones = gestiones; | ||||
| @ -101,4 +102,12 @@ class Mes{ | ||||
| 		return this.gestiones; | ||||
| 	} | ||||
| 	 | ||||
| 	float getTotal() { | ||||
| 		float ret = 0; | ||||
| 		for(Gestion gestion:this.gestiones) { | ||||
| 			ret += gestion.getTotal(); | ||||
| 		} | ||||
| 		return ret; | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|  | ||||
| @ -74,21 +74,12 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen | ||||
| 				} | ||||
| 				break; | ||||
| 			} | ||||
| 			 | ||||
| 			case "Eliminar Transacciones":{ | ||||
| 				this.menu.pestanias.get(this.menu.pestania.getSelectedIndex()).eliminarDeseleccionados(); | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		/*if(e.getActionCommand().equals(this.vista.mostrarEstadisticas.getActionCommand())) { | ||||
| 			 | ||||
| 			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); | ||||
| 		} | ||||
| 		*/ | ||||
| 	} | ||||
| 	 | ||||
| 	private void aniadirElementos() { | ||||
| @ -101,6 +92,8 @@ public class ControladorPanelLateral implements ActionListener, DateChangeListen | ||||
| 			this.mes=VistaPanelLateral.elegirMes.getDate().getMonth(); | ||||
| 			this.anio=VistaPanelLateral.elegirMes.getDate().getYear(); | ||||
| 		} | ||||
| 		this.vista.eliminarTransaccion.addActionListener(this); | ||||
| 		this.vista.eliminarTransaccion.setActionCommand("Eliminar Transacciones"); | ||||
| 	} | ||||
| 
 | ||||
| 	public void dateChanged(DateChangeEvent arg0) { | ||||
|  | ||||
| @ -35,7 +35,7 @@ public class Menu extends JFrame{ | ||||
| 		this.cargarPestanias(); | ||||
| 		this.setLayout(new GridBagLayout()); | ||||
| 		GridBagConstraints constrain = new GridBagConstraints(); | ||||
| 		this.panel = new VistaPanelLateral(constrain); | ||||
| 		this.panel = new VistaPanelLateral(constrain, this.meses); | ||||
| 		this.panelCentral = new JPanel(); | ||||
| 		 | ||||
| 		constrain.fill = GridBagConstraints.VERTICAL; | ||||
| @ -77,7 +77,6 @@ public class Menu extends JFrame{ | ||||
| 		this.meses.elegirMes(anio, mes); | ||||
| 		if(this.meses.getGestionesActuales().size() == 0) { | ||||
| 			this.iniciarMes(anio, mes); | ||||
| 			System.out.println("entra"); | ||||
| 		}else { | ||||
| 			this.cargarMes(); | ||||
| 		} | ||||
|  | ||||
| @ -21,7 +21,7 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 	JScrollPane panel; | ||||
| 	Menu menu; | ||||
| 	private ControladorAniadirVisualizar controlador; | ||||
| 	static VistaPanelLateral panelLateral; | ||||
| 	private static VistaPanelLateral panelLateral; | ||||
| 	public VistaAniadirVisualizar(Menu menu, Gestion gestion) { | ||||
| 		this.gestiones = gestion; | ||||
| 		this.transacciones = new LinkedList<JCheckBox>(); | ||||
| @ -68,6 +68,16 @@ public class VistaAniadirVisualizar extends JPanel{ | ||||
| 		this.repaint(); | ||||
| 	} | ||||
| 	 | ||||
| 	void eliminarDeseleccionados(){ | ||||
| 		for(JCheckBox check:this.transacciones) { | ||||
| 			if(!check.isSelected()) { | ||||
| 				this.cuadro.remove(check); | ||||
| 				this.gestiones.eliminarTransaccion(check.getText()); | ||||
| 				this.cuadro.revalidate(); | ||||
| 				this.cuadro.repaint(); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	private void aniadirElemento(Transaccion transaccion) { | ||||
| 		JCheckBox check = new JCheckBox(transaccion.toString()); | ||||
|  | ||||
| @ -12,16 +12,19 @@ import javax.swing.JTextArea; | ||||
| import com.github.lgooddatepicker.components.DatePicker; | ||||
| 
 | ||||
| import Logica.Gestion; | ||||
| import Logica.Meses; | ||||
| 
 | ||||
| public class VistaPanelLateral extends JPanel{ | ||||
| 	protected JTextArea total; | ||||
| 	protected JTextArea gastoEnvio; | ||||
| 	//protected JButton elegirMes; | ||||
| 	protected static DatePicker elegirMes = inicializarCalendario(); | ||||
| 	protected JButton mostrarEstadisticas; | ||||
| 	JButton aniadirGestion; | ||||
| 	VistaPanelLateral(GridBagConstraints constrain){ | ||||
| 	JButton eliminarTransaccion; | ||||
| 	Meses meses; | ||||
| 	VistaPanelLateral(GridBagConstraints constrain, Meses meses){ | ||||
| 		this.setPreferredSize(new Dimension(200,200)); | ||||
| 		this.meses=meses; | ||||
| 		this.total = new JTextArea(); | ||||
| 		this.gastoEnvio = new JTextArea(); | ||||
| 		this.mostrarEstadisticas = new JButton("Mostrar grafico del mes"); | ||||
| @ -40,10 +43,12 @@ public class VistaPanelLateral extends JPanel{ | ||||
| 		constrain.weightx = 2; | ||||
| 		this.add(this.gastoEnvio); | ||||
| 		this.add(this.aniadirGestion); | ||||
| 		this.eliminarTransaccion = new JButton("Eliminar Deseleccionados"); | ||||
| 		this.add(this.eliminarTransaccion); | ||||
| 	} | ||||
| 	 | ||||
| 	void actualizarDatos(Gestion gestion) { | ||||
| 		this.total.setText("Total: " + String.valueOf(Gestion.getTotal()) + "€"); | ||||
| 		this.total.setText("Total: " + String.valueOf(this.meses.getTotal()) + "€"); | ||||
| 		this.gastoEnvio.setText("Suma: " + String.valueOf(gestion.getSuma()) + "€"); | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user