Advertisement
Guest User

Código StackOWFL

a guest
Aug 25th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.69 KB | None | 0 0
  1. Aquí el codigo de la clase Ventana1:
  2.  
  3. import java.awt.Container;
  4. import java.awt.FlowLayout;
  5. import java.util.ArrayList;
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JLabel;
  9. import javax.swing.JSeparator;
  10. import javax.swing.JTextField;
  11. import javax.swing.SwingConstants;
  12. import java.awt.event.MouseAdapter;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15.  
  16. public class Ventana1 extends JFrame implements ActionListener {
  17.    
  18.     static ArrayList<Cliente>listaClientes=new ArrayList<Cliente>();
  19.    
  20.     public void obtenerTexto() {
  21.        
  22.         }
  23.     Ventana1(){
  24.        
  25.         ActionListener accion1= new ActionListener() {
  26.            
  27.             public void actionPerformed(ActionEvent e) {
  28.                 if(e.getSource()==btn1) {
  29.                     String texto1= campo2.getText();
  30.                     if(texto1!=null) {
  31.                        
  32.                     }
  33.                 }
  34.  
  35.             }
  36.         };
  37.         ActionListener accion2= new ActionListener() {
  38.             public void actionPerformed(ActionEvent e) {
  39.                
  40.             }
  41.         };
  42.         ActionListener accion3= new ActionListener() {
  43.             public void actionPerformed(ActionEvent e) {
  44.                
  45.             }
  46.         };
  47.         ActionListener accion4= new ActionListener() {
  48.             public void actionPerformed(ActionEvent e) {
  49.                
  50.             }
  51.         };
  52.         //Se crea el título, dimensiones de ventana y la visibilidad
  53.         setTitle("Alta de cliente");
  54.         setBounds(0, 0, 700, 350);
  55.         setLocationRelativeTo(null);
  56.         setVisible(true);
  57.  
  58.         //Se crea el contenedor
  59.         Container cp = getContentPane();
  60.         FlowLayout flow = new  FlowLayout();
  61.         cp.setLayout(null);
  62.  
  63.         //Nuevo Cliente
  64.         JLabel texto1 = new JLabel("Nuevo Cliente");
  65.         texto1.setBounds(70, 30, 90, 40);
  66.  
  67.         JLabel texto2 = new JLabel("Nombre: ");
  68.         texto2.setBounds(50, 60, 70, 40);
  69.  
  70.         JTextField campo2 = new JTextField();
  71.         campo2.setBounds(110, 70, 150, 20);
  72.  
  73.         JLabel texto3 = new JLabel("Apellido:");
  74.         texto3.setBounds(50, 90, 70, 40);
  75.  
  76.         JTextField campo3 = new JTextField(null);
  77.         campo3.setBounds(110, 100, 150, 20);
  78.  
  79.         JLabel texto4 = new JLabel("Edad:");
  80.         texto4.setBounds(50, 120, 140, 40);
  81.  
  82.         JTextField campo4 = new JTextField(null);
  83.         campo4.setBounds(110, 130, 150, 20);
  84.  
  85.         JButton btn1 = new JButton("Ingresar");
  86.         btn1.setBounds(50, 190, 100, 20);
  87.        
  88.         JButton btn2 = new JButton("Borrar");
  89.         btn2.setBounds(180, 190, 100, 20);
  90.  
  91.         //Lista
  92.         JLabel texto5 = new JLabel("Cliente # de la lista");
  93.         texto5.setBounds(400, 30, 130, 40);
  94.  
  95.         JLabel texto6 = new JLabel("Nombre: ");
  96.         texto6.setBounds(380, 60, 70, 40);
  97.  
  98.         JTextField campo5 = new JTextField(null);
  99.         campo5.setBounds(440, 70, 150, 20);
  100.  
  101.         JLabel texto7 = new JLabel("Apellido:");
  102.         texto7.setBounds(380, 90, 70, 40);
  103.  
  104.         JTextField campo6 = new JTextField(null);
  105.         campo6.setBounds(440, 100, 150, 20);
  106.  
  107.         JLabel texto8 = new JLabel("Edad:");
  108.         texto8.setBounds(380, 120, 140, 40);
  109.  
  110.         JTextField campo7 = new JTextField(null);
  111.         campo7.setBounds(440, 130, 150, 20);
  112.  
  113.         JButton btn3 = new JButton("<");
  114.         btn3.setBounds(380, 190, 100, 20);
  115.  
  116.         JButton btn4 = new JButton(">");
  117.         btn4.setBounds(510, 190, 100, 20);
  118.  
  119.         JSeparator sep1 = new JSeparator(SwingConstants.VERTICAL);
  120.         sep1.setBounds(328, 0, 10, 320);
  121.  
  122.         JSeparator sep2 = new JSeparator(SwingConstants.VERTICAL);
  123.         sep2.setBounds(332, 0, 10, 320);
  124.  
  125.         cp.add(texto1);
  126.         cp.add(texto2);
  127.         cp.add(texto3);
  128.         cp.add(texto4);
  129.         cp.add(campo2);
  130.         cp.add(campo3);
  131.         cp.add(campo4);
  132.         cp.add(btn1);
  133.         cp.add(btn2);
  134.  
  135.         cp.add(texto5);
  136.         cp.add(texto6);
  137.         cp.add(texto7);
  138.         cp.add(texto8);
  139.         cp.add(campo5);
  140.         cp.add(campo6);
  141.         cp.add(campo7);
  142.         cp.add(btn3);
  143.         cp.add(btn4);
  144.  
  145.         cp.add(sep1);
  146.         cp.add(sep2);
  147.        
  148.         btn1.addActionListener(accion1);
  149.         btn2.addActionListener(accion2);
  150.         btn3.addActionListener(accion3);
  151.         btn4.addActionListener(accion4);
  152.         this.repaint();
  153.     }
  154.  
  155.     public static void main(String[] args) {
  156.         Ventana1 mi_ventana = new Ventana1();
  157.  
  158.     }
  159.  
  160.     @Override
  161.     public void actionPerformed(ActionEvent e) {
  162.         // TODO Auto-generated method stub
  163.        
  164.     }
  165. }
  166.  
  167.  
  168.  
  169. Y aquí el código de la clase Cliente:
  170.  
  171.     import java.util.ArrayList;
  172.  
  173.     public class Cliente {
  174.    
  175.     private String nombre;
  176.     private String apellido;
  177.     private int edad;
  178.     private Ventana1 ventana1;
  179.    
  180.    
  181.     public Cliente(String nombre, String apellido, int edad) {
  182.         this.nombre=nombre;
  183.         this.apellido=apellido;
  184.         this.edad=edad;
  185.     }
  186.  
  187.    
  188.     public String getNombre() {
  189.         return nombre;
  190.     }
  191.     public void setNombre() {
  192.         this.nombre=nombre;
  193.     }
  194.     public String getApellido() {
  195.         return apellido;
  196.     }
  197.     public void setApellido() {
  198.         this.apellido=apellido;
  199.     }
  200.     public int getEdad() {
  201.         return edad;
  202.     }
  203.     public void setEdad() {
  204.         this.edad=edad;
  205.     }
  206.    
  207.     public void agregarCli() {
  208.         Ventana1.listaClientes.add(new Cliente(getNombre(), getApellido(), getEdad()));
  209.     }
  210.    
  211.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement