From 386e847a277c59aef36fc98d5b57894496f016ee Mon Sep 17 00:00:00 2001 From: roche Date: Thu, 7 Nov 2019 16:01:52 +0100 Subject: [PATCH] init --- .classpath | 6 ++++ .project | 17 ++++++++++ .settings/org.eclipse.jdt.core.prefs | 11 +++++++ bin/.gitignore | 3 ++ src/Logica/Gestion.java | 43 ++++++++++++++++++++++++ src/Logica/Transaccion.java | 34 +++++++++++++++++++ src/Main.java | 11 +++++++ src/VistaControlador/CheckBoxList.java | 28 ++++++++++++++++ src/VistaControlador/Controlador.java | 34 +++++++++++++++++++ src/VistaControlador/Menu.java | 40 +++++++++++++++++++++++ src/VistaControlador/Vista.java | 45 ++++++++++++++++++++++++++ 11 files changed, 272 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 bin/.gitignore create mode 100644 src/Logica/Gestion.java create mode 100644 src/Logica/Transaccion.java create mode 100644 src/Main.java create mode 100644 src/VistaControlador/CheckBoxList.java create mode 100644 src/VistaControlador/Controlador.java create mode 100644 src/VistaControlador/Menu.java create mode 100644 src/VistaControlador/Vista.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..51a8bba --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..476f77a --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + TrabajoInterfaces + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..794f95c --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,3 @@ +/Logica/ +/Main.class +/VistaControlador/ diff --git a/src/Logica/Gestion.java b/src/Logica/Gestion.java new file mode 100644 index 0000000..9d74c1e --- /dev/null +++ b/src/Logica/Gestion.java @@ -0,0 +1,43 @@ +package Logica; +import java.util.Vector; + +public class Gestion{ + private Vector gestiones; + private int suma; + private static int total; + + public Gestion() { + this.gestiones=new Vector(); + 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 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(); + } + } +} diff --git a/src/Logica/Transaccion.java b/src/Logica/Transaccion.java new file mode 100644 index 0000000..1ad6a1a --- /dev/null +++ b/src/Logica/Transaccion.java @@ -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; + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..f4c8fae --- /dev/null +++ b/src/Main.java @@ -0,0 +1,11 @@ +import VistaControlador.Menu; + +public class Main { + + public static void main(String[] args) { + Menu menu=new Menu(); + menu.setVisible(true); + + } + +} diff --git a/src/VistaControlador/CheckBoxList.java b/src/VistaControlador/CheckBoxList.java new file mode 100644 index 0000000..5de3ef2 --- /dev/null +++ b/src/VistaControlador/CheckBoxList.java @@ -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 extends JCheckBox implements ListCellRenderer { + + private static final long serialVersionUID = 3734536442230283966L; + + @Override + public Component getListCellRendererComponent(JList 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; + } +} diff --git a/src/VistaControlador/Controlador.java b/src/VistaControlador/Controlador.java new file mode 100644 index 0000000..d31b18a --- /dev/null +++ b/src/VistaControlador/Controlador.java @@ -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); + } + +} diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java new file mode 100644 index 0000000..1144b92 --- /dev/null +++ b/src/VistaControlador/Menu.java @@ -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); + } + +} diff --git a/src/VistaControlador/Vista.java b/src/VistaControlador/Vista.java new file mode 100644 index 0000000..6698d4c --- /dev/null +++ b/src/VistaControlador/Vista.java @@ -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(); + } +}