init
This commit is contained in:
		
						commit
						386e847a27
					
				
							
								
								
									
										6
									
								
								.classpath
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.classpath
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <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="output" path="bin"/> | ||||
| </classpath> | ||||
							
								
								
									
										17
									
								
								.project
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.project
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <projectDescription> | ||||
| 	<name>TrabajoInterfaces</name> | ||||
| 	<comment></comment> | ||||
| 	<projects> | ||||
| 	</projects> | ||||
| 	<buildSpec> | ||||
| 		<buildCommand> | ||||
| 			<name>org.eclipse.jdt.core.javabuilder</name> | ||||
| 			<arguments> | ||||
| 			</arguments> | ||||
| 		</buildCommand> | ||||
| 	</buildSpec> | ||||
| 	<natures> | ||||
| 		<nature>org.eclipse.jdt.core.javanature</nature> | ||||
| 	</natures> | ||||
| </projectDescription> | ||||
							
								
								
									
										11
									
								
								.settings/org.eclipse.jdt.core.prefs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								.settings/org.eclipse.jdt.core.prefs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| eclipse.preferences.version=1 | ||||
| org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||||
| org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||||
| org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||||
| org.eclipse.jdt.core.compiler.compliance=1.8 | ||||
| org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||||
| org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||||
| org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||||
| org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||||
| org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||||
| org.eclipse.jdt.core.compiler.source=1.8 | ||||
							
								
								
									
										3
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								bin/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| /Logica/ | ||||
| /Main.class | ||||
| /VistaControlador/ | ||||
							
								
								
									
										43
									
								
								src/Logica/Gestion.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/Logica/Gestion.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| package Logica; | ||||
| import java.util.Vector; | ||||
| 
 | ||||
| public class Gestion{ | ||||
| 	private Vector<Transaccion> gestiones; | ||||
| 	private int suma; | ||||
| 	private static int total; | ||||
| 	 | ||||
| 	public Gestion() { | ||||
| 		this.gestiones=new Vector<Transaccion>(); | ||||
| 		this.suma=0; | ||||
| 		Gestion.total=0; | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirGasto(String nombre, int dinero) { | ||||
| 		this.gestiones.add(new Transaccion(nombre, dinero)); | ||||
| 		this.suma+=dinero; | ||||
| 		Gestion.total+=total; | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirGasto(Transaccion transaccion) { | ||||
| 		this.gestiones.add(transaccion); | ||||
| 	} | ||||
| 	 | ||||
| 	public int getSuma() { | ||||
| 		return this.suma; | ||||
| 	} | ||||
| 	 | ||||
| 	public int getTotal() { | ||||
| 		return Gestion.total; | ||||
| 	} | ||||
| 	 | ||||
| 	public Vector<Transaccion> getElementos(){ | ||||
| 		return this.gestiones; | ||||
| 	} | ||||
| 	 | ||||
| 	public void alterarVisibilidad(boolean visibilidad, int elemento) { | ||||
| 		if(this.gestiones.get(elemento).alterarVisivilidad(visibilidad)) { | ||||
| 			this.suma-=this.gestiones.get(elemento).getDinero(); | ||||
| 			Gestion.total-=this.gestiones.get(elemento).getDinero(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										34
									
								
								src/Logica/Transaccion.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/Logica/Transaccion.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| package Logica; | ||||
| 
 | ||||
| public class Transaccion { | ||||
| 	private String nombre; | ||||
| 	private int dinero; | ||||
| 	private boolean visible; | ||||
| 	 | ||||
| 	public Transaccion(String nombre, int dinero){ | ||||
| 		this.nombre=nombre; | ||||
| 		this.dinero=dinero; | ||||
| 		this.visible=true; | ||||
| 	} | ||||
| 	 | ||||
| 	public String toString() { | ||||
| 		return this.nombre+" "+this.dinero; | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getVisivilidad() { | ||||
| 		return this.visible; | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean alterarVisivilidad(boolean visibilidad) { | ||||
| 		if(this.visible!=visibilidad) { | ||||
| 			this.visible=visibilidad; | ||||
| 			return true; | ||||
| 		}else { | ||||
| 			return false; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public int getDinero() { | ||||
| 		return this.dinero; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										11
									
								
								src/Main.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Main.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| import VistaControlador.Menu; | ||||
| 
 | ||||
| public class Main { | ||||
| 
 | ||||
| 	public static void main(String[] args) { | ||||
| 		Menu menu=new Menu(); | ||||
| 		menu.setVisible(true); | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										28
									
								
								src/VistaControlador/CheckBoxList.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/VistaControlador/CheckBoxList.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| package VistaControlador; | ||||
| 
 | ||||
| import java.awt.Component; | ||||
| import java.awt.List; | ||||
| 
 | ||||
| import javax.swing.JCheckBox; | ||||
| import javax.swing.JList; | ||||
| import javax.swing.ListCellRenderer; | ||||
| 
 | ||||
| class CheckBoxList<E> extends JCheckBox implements ListCellRenderer<E> { | ||||
| 	  | ||||
| 	private static final long serialVersionUID = 3734536442230283966L; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Component getListCellRendererComponent(JList<? extends E> list,E value, int index, boolean isSelected, boolean cellHasFocus) { | ||||
| 		setComponentOrientation(list.getComponentOrientation()); | ||||
| 
 | ||||
| 		setFont(list.getFont()); | ||||
| 		setText(String.valueOf(value)); | ||||
| 
 | ||||
| 		setBackground(list.getBackground()); | ||||
| 		setForeground(list.getForeground()); | ||||
| 
 | ||||
| 		setSelected(isSelected); | ||||
| 		setEnabled(list.isEnabled()); | ||||
| 		return this; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										34
									
								
								src/VistaControlador/Controlador.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/VistaControlador/Controlador.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,34 @@ | ||||
| package VistaControlador; | ||||
| 
 | ||||
| import java.awt.event.ActionEvent; | ||||
| import java.awt.event.ActionListener; | ||||
| 
 | ||||
| import javax.swing.JFrame; | ||||
| import javax.swing.JTextField; | ||||
| 
 | ||||
| public class Controlador implements ActionListener{ | ||||
| 
 | ||||
| 	private Vista vista; | ||||
| 	public Controlador(Vista vista) { | ||||
| 		this.vista=vista; | ||||
| 		this.aniadirListeners(); | ||||
| 	} | ||||
| 	@Override | ||||
| 	public void actionPerformed(ActionEvent e) { | ||||
| 		String nombre="hola"; | ||||
| 		int dinero=0; | ||||
| 		JFrame pedir=new JFrame(); | ||||
| 		JTextField iNombre=new JTextField("nombre"); | ||||
| 		JTextField iDinero=new JTextField("0"); | ||||
| 		pedir.add(iNombre); | ||||
| 		pedir.add(iDinero); | ||||
| 		//pedir.setVisible(true); | ||||
| 		this.vista.aniadirElemento(iNombre.getText(), Integer.parseInt(iDinero.getText())); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	private void aniadirListeners() { | ||||
| 		vista.boton.addActionListener(this); | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
							
								
								
									
										40
									
								
								src/VistaControlador/Menu.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								src/VistaControlador/Menu.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | ||||
| package VistaControlador; | ||||
| 
 | ||||
| import java.awt.Dimension; | ||||
| 
 | ||||
| import javax.swing.JButton; | ||||
| import javax.swing.JComponent; | ||||
| import javax.swing.JFrame; | ||||
| import javax.swing.JPanel; | ||||
| import javax.swing.JTabbedPane; | ||||
| 
 | ||||
| public class Menu extends JFrame{ | ||||
| 	protected JPanel panelCentral; | ||||
| 	protected JTabbedPane pestania; | ||||
| 	protected Vista ingresos; | ||||
| 	protected Vista gastos; | ||||
| 	 | ||||
| 	public Menu() { | ||||
| 		init(); | ||||
| 	} | ||||
| 	 | ||||
| 	private void init() { | ||||
| 		this.ingresos=new Vista(); | ||||
| 		this.gastos=new Vista(); | ||||
| 		this.panelCentral=new JPanel(); | ||||
| 		this.pestania=new JTabbedPane(); | ||||
| 		this.panelCentral.add(pestania); | ||||
| 		this.gastos=new Vista(); | ||||
| 		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); | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
							
								
								
									
										45
									
								
								src/VistaControlador/Vista.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/VistaControlador/Vista.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| package VistaControlador; | ||||
| 
 | ||||
| import java.awt.Dimension; | ||||
| import javax.swing.JButton; | ||||
| import javax.swing.JCheckBox; | ||||
| import javax.swing.JPanel; | ||||
| import javax.swing.JScrollPane; | ||||
| 
 | ||||
| import Logica.*; | ||||
| 
 | ||||
| public class Vista extends JPanel{ | ||||
| 	private int x,y; | ||||
| 	private Gestion gestiones; | ||||
| 	protected JButton boton; | ||||
| 	JPanel cuadro; | ||||
| 	JScrollPane panel; | ||||
| 	public Vista() { | ||||
| 		this.x=100; | ||||
| 		this.boton=new JButton("aniadir"); | ||||
| 		this.gestiones=new Gestion(); | ||||
| 		this.add(boton); | ||||
| 		this.cuadro=new JPanel(); | ||||
| 		this.panel=new JScrollPane(cuadro); | ||||
| 		this.panel.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); | ||||
| 		this.panel.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); | ||||
| 		cuadro.setPreferredSize(new Dimension(x, y)); | ||||
| 		panel.setPreferredSize(new Dimension(100,400)); | ||||
| 		panel.setVisible(true); | ||||
| 		this.add(panel); | ||||
| 		this.aniadirElemento("asdfa", 0); | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| 	public void aniadirElemento(String nombre, int dinero) { | ||||
| 		Transaccion transaccion=new Transaccion(nombre, dinero); | ||||
| 		this.gestiones.aniadirGasto(transaccion); | ||||
| 		JCheckBox check=new JCheckBox(transaccion.toString()); | ||||
| 		this.cuadro.add(check); | ||||
| 		this.y+=28; | ||||
| 		//System.out.println(this.y); | ||||
| 		cuadro.setPreferredSize(new Dimension(x, y)); | ||||
| 		this.revalidate(); | ||||
| 		this.repaint(); | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user