diff --git a/bin/.gitignore b/bin/.gitignore index 794f95c..e809c4c 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,3 +1,2 @@ -/Logica/ -/Main.class /VistaControlador/ +/PedirDatos/ diff --git a/src/VistaControlador/Controlador.java b/src/VistaControlador/Controlador.java index d31b18a..dcd9237 100644 --- a/src/VistaControlador/Controlador.java +++ b/src/VistaControlador/Controlador.java @@ -2,9 +2,7 @@ package VistaControlador; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - -import javax.swing.JFrame; -import javax.swing.JTextField; +import javax.swing.JOptionPane; public class Controlador implements ActionListener{ @@ -15,15 +13,23 @@ public class Controlador implements ActionListener{ } @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())); + String nombre=JOptionPane.showInputDialog("Introduce un nuevo gasto o ingreso"); + if(nombre.equals("")) { + JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); + return; + } + String dinero=JOptionPane.showInputDialog("Introduce a cuanto asciende"); + if(dinero.equals("")) { + JOptionPane.showMessageDialog(null, "Debe introducir algo", "error", JOptionPane.WARNING_MESSAGE); + return; + } + + try { + this.vista.aniadirElemento(nombre, Integer.parseInt(dinero)); + }catch (NumberFormatException ex) { + JOptionPane.showMessageDialog(null, "Debe introducir un numero", "error", JOptionPane.WARNING_MESSAGE); + } + } diff --git a/src/VistaControlador/Menu.java b/src/VistaControlador/Menu.java index 1144b92..b9b3710 100644 --- a/src/VistaControlador/Menu.java +++ b/src/VistaControlador/Menu.java @@ -2,8 +2,6 @@ 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; @@ -19,12 +17,11 @@ public class Menu extends JFrame{ } private void init() { - this.ingresos=new Vista(); - this.gastos=new Vista(); + this.ingresos=new Vista(this); + this.gastos=new Vista(this); 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); diff --git a/src/VistaControlador/Vista.java b/src/VistaControlador/Vista.java index 6698d4c..f70e020 100644 --- a/src/VistaControlador/Vista.java +++ b/src/VistaControlador/Vista.java @@ -3,6 +3,7 @@ package VistaControlador; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -12,9 +13,10 @@ public class Vista extends JPanel{ private int x,y; private Gestion gestiones; protected JButton boton; + protected JFrame padre; JPanel cuadro; JScrollPane panel; - public Vista() { + public Vista(JFrame padre) { this.x=100; this.boton=new JButton("aniadir"); this.gestiones=new Gestion(); @@ -24,11 +26,11 @@ public class Vista extends JPanel{ 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.setPreferredSize(new Dimension(100,200)); panel.setVisible(true); this.add(panel); this.aniadirElemento("asdfa", 0); - + this.padre=padre; } public void aniadirElemento(String nombre, int dinero) {