Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Aquí el codigo de la clase Ventana1:
- import java.awt.Container;
- import java.awt.FlowLayout;
- import java.util.ArrayList;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JSeparator;
- import javax.swing.JTextField;
- import javax.swing.SwingConstants;
- import java.awt.event.MouseAdapter;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Ventana1 extends JFrame implements ActionListener {
- static ArrayList<Cliente>listaClientes=new ArrayList<Cliente>();
- public void obtenerTexto() {
- }
- Ventana1(){
- ActionListener accion1= new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource()==btn1) {
- String texto1= campo2.getText();
- if(texto1!=null) {
- }
- }
- }
- };
- ActionListener accion2= new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- };
- ActionListener accion3= new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- };
- ActionListener accion4= new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- };
- //Se crea el título, dimensiones de ventana y la visibilidad
- setTitle("Alta de cliente");
- setBounds(0, 0, 700, 350);
- setLocationRelativeTo(null);
- setVisible(true);
- //Se crea el contenedor
- Container cp = getContentPane();
- FlowLayout flow = new FlowLayout();
- cp.setLayout(null);
- //Nuevo Cliente
- JLabel texto1 = new JLabel("Nuevo Cliente");
- texto1.setBounds(70, 30, 90, 40);
- JLabel texto2 = new JLabel("Nombre: ");
- texto2.setBounds(50, 60, 70, 40);
- JTextField campo2 = new JTextField();
- campo2.setBounds(110, 70, 150, 20);
- JLabel texto3 = new JLabel("Apellido:");
- texto3.setBounds(50, 90, 70, 40);
- JTextField campo3 = new JTextField(null);
- campo3.setBounds(110, 100, 150, 20);
- JLabel texto4 = new JLabel("Edad:");
- texto4.setBounds(50, 120, 140, 40);
- JTextField campo4 = new JTextField(null);
- campo4.setBounds(110, 130, 150, 20);
- JButton btn1 = new JButton("Ingresar");
- btn1.setBounds(50, 190, 100, 20);
- JButton btn2 = new JButton("Borrar");
- btn2.setBounds(180, 190, 100, 20);
- //Lista
- JLabel texto5 = new JLabel("Cliente # de la lista");
- texto5.setBounds(400, 30, 130, 40);
- JLabel texto6 = new JLabel("Nombre: ");
- texto6.setBounds(380, 60, 70, 40);
- JTextField campo5 = new JTextField(null);
- campo5.setBounds(440, 70, 150, 20);
- JLabel texto7 = new JLabel("Apellido:");
- texto7.setBounds(380, 90, 70, 40);
- JTextField campo6 = new JTextField(null);
- campo6.setBounds(440, 100, 150, 20);
- JLabel texto8 = new JLabel("Edad:");
- texto8.setBounds(380, 120, 140, 40);
- JTextField campo7 = new JTextField(null);
- campo7.setBounds(440, 130, 150, 20);
- JButton btn3 = new JButton("<");
- btn3.setBounds(380, 190, 100, 20);
- JButton btn4 = new JButton(">");
- btn4.setBounds(510, 190, 100, 20);
- JSeparator sep1 = new JSeparator(SwingConstants.VERTICAL);
- sep1.setBounds(328, 0, 10, 320);
- JSeparator sep2 = new JSeparator(SwingConstants.VERTICAL);
- sep2.setBounds(332, 0, 10, 320);
- cp.add(texto1);
- cp.add(texto2);
- cp.add(texto3);
- cp.add(texto4);
- cp.add(campo2);
- cp.add(campo3);
- cp.add(campo4);
- cp.add(btn1);
- cp.add(btn2);
- cp.add(texto5);
- cp.add(texto6);
- cp.add(texto7);
- cp.add(texto8);
- cp.add(campo5);
- cp.add(campo6);
- cp.add(campo7);
- cp.add(btn3);
- cp.add(btn4);
- cp.add(sep1);
- cp.add(sep2);
- btn1.addActionListener(accion1);
- btn2.addActionListener(accion2);
- btn3.addActionListener(accion3);
- btn4.addActionListener(accion4);
- this.repaint();
- }
- public static void main(String[] args) {
- Ventana1 mi_ventana = new Ventana1();
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- }
- }
- Y aquí el código de la clase Cliente:
- import java.util.ArrayList;
- public class Cliente {
- private String nombre;
- private String apellido;
- private int edad;
- private Ventana1 ventana1;
- public Cliente(String nombre, String apellido, int edad) {
- this.nombre=nombre;
- this.apellido=apellido;
- this.edad=edad;
- }
- public String getNombre() {
- return nombre;
- }
- public void setNombre() {
- this.nombre=nombre;
- }
- public String getApellido() {
- return apellido;
- }
- public void setApellido() {
- this.apellido=apellido;
- }
- public int getEdad() {
- return edad;
- }
- public void setEdad() {
- this.edad=edad;
- }
- public void agregarCli() {
- Ventana1.listaClientes.add(new Cliente(getNombre(), getApellido(), getEdad()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement