init
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user