Taller interfaz 2

327 views
221 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
327
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Taller interfaz 2

  1. 1. import javax.swing.*;import java.awt.event.*;public class Formulario extends JFrame implements ActionListener {JButton boton1;public Formulario() {setLayout(null);boton1=new JButton("Dale Aqui No Pasara Nada ");boton1.setBounds(10,10,300,30);add(boton1);boton1.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource()==boton1) {System.exit(0);}}public static void main(String[] args) {Formulario formulario1=new Formulario();formulario1.setBounds(0,0,450,350);formulario1.setVisible(true);}}-----------------------------------------------------------------------------------------------------------import javax.swing.*;import java.awt.event.*;public class Formulario1 extends JFrame implements ActionListener{
  2. 2. private JButton boton1,boton2,boton3;public Formulario1() {setLayout(null);boton1=new JButton("1");boton1.setBounds(10,100,90,30);add(boton1);boton1.addActionListener(this);boton2=new JButton("2");boton2.setBounds(110,100,90,30);add(boton2);boton2.addActionListener(this);boton3=new JButton("3");boton3.setBounds(210,100,90,30);add(boton3);boton3.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource()==boton1) {setTitle("boton 1");}if (e.getSource()==boton2) {setTitle("boton 2");}if (e.getSource()==boton3) {setTitle("boton 3");}
  3. 3. }public static void main(String[] ar){Formulario1 formulario1=new Formulario1();formulario1.setBounds(0,0,350,200);formulario1.setVisible(true);formulario1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}-----------------------------------------------------------------------------------------------------------import javax.swing.*;import java.awt.event.*;public class Hombre_Mujer extends JFrame implements ActionListener{private JButton boton1,boton2;public Hombre_Mujer() {setLayout(null);boton1=new JButton("Varon");boton1.setBounds(250,100,90,30);add(boton1);boton1.addActionListener(this);boton2=new JButton("Mujer");boton2.setBounds(250,150,90,30);add(boton2);boton2.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource()==boton1) {
  4. 4. JOptionPane.showMessageDialog(null,"Varon");System.exit(0);}if (e.getSource()==boton2) {JOptionPane.showMessageDialog(null,"Mujer");System.exit(0);}}public static void main(String[] ar){Hombre_Mujer formulario2=new Hombre_Mujer();formulario2.setBounds(0,0,500,500);formulario2.setVisible(true);formulario2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}-----------------------------------------------------------------------------------------------------------import java.awt.*;import java.awt.event.*;import javax.swing.*;public class PruebaCampoTexto extends JFrame{privateJTextField campoTexto1, campoTexto2, campoTexto3, campoTexto4;privateJPasswordFieldcampoContrasenia;// configurar GUIpublicPruebaCampoTexto(){super( "Prueba de JTextField y JPasswordField" );Container contenedor = getContentPane();
  5. 5. contenedor.setLayout( new FlowLayout() );// crear campo de texto con tamaño predeterminadocampoTexto1 = new JTextField( 10 );contenedor.add( campoTexto1 );// crear campo de texto con texto predeterminadocampoTexto2 = new JTextField( "Escriba el texto aquí" );contenedor.add( campoTexto2 );// crear campo de texto con texto predeterminadocampoTexto4 = new JTextField( "Mi Creacion .___." );contenedor.add( campoTexto4 );// crear campo de texto con texto predeterminado,// 20 elementos visibles y sin manejador de eventoscampoTexto3 = new JTextField( "Campo de texto no editable", 20 );campoTexto3.setEditable( false );campoTexto3.setToolTipText("No se edita");contenedor.add( campoTexto3 );// crear campo de contraseña con texto predeterminadocampoContrasenia = new JPasswordField( "Texto oculto" );contenedor.add(campoContrasenia );// registrar manejadores de eventosManejadorCampoTexto manejador = new ManejadorCampoTexto();campoTexto1.addActionListener( manejador );campoTexto2.addActionListener( manejador );campoTexto3.addActionListener( manejador );campoTexto4.addActionListener( manejador );campoContrasenia.addActionListener( manejador );
  6. 6. setSize( 400, 200 );setVisible( true );} // fin del constructor de PruebaCampoTextopublic static void main( String args[] ){PruebaCampoTextoaplicacion = new PruebaCampoTexto();aplicacion.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );}// clase interna privada para el manejo de eventosprivateclassManejadorCampoTextoimplementsActionListener{// procesar eventos de campo de textopublic void actionPerformed( ActionEvent evento ){String cadena = "";// el usuario oprimió Intro en objeto JTextField campoTexto1if ( evento.getSource() == campoTexto1 )cadena = "campoTexto1: " + evento.getActionCommand();// el usuario oprimió Intro en objeto JTextField campoTexto2else if ( evento.getSource() == campoTexto2 )cadena = "campoTexto2: " + evento.getActionCommand();// el usuario oprimió Intro en objeto JTextField campoTexto3else if ( evento.getSource() == campoTexto3 )cadena = "campoTexto3: " + evento.getActionCommand();// el usuario oprimió Intro en objeto JTextField campoTexto2else if ( evento.getSource() == campoTexto4 )cadena = "campoTexto4: " +evento.getActionCommand();// el usuario oprimió Intro en objeto JTextFieldcampoContrasenia
  7. 7. else if ( evento.getSource() == campoContrasenia ){cadena = "campoContrasenia: " +newString(campoContrasenia.getPassword() );}JOptionPane.showMessageDialog( null,cadena,"Resultados",JOptionPane.CANCEL_OPTION);}}}-----------------------------------------------------------------------------------------------------------import javax.swing.*;import java.awt.event.*;public class Cajero extends JFrame implements ActionListener{privateJButtonsaldo,consignar,retirar,salir;//Clase Cajeropublic Cajero() {setLayout(null);//Boton De Saldosaldo=new JButton("SALDO");saldo.setBounds(250,100,120,30);add(saldo);saldo.addActionListener(this);//Boton De Consignarconsignar=new JButton("CONSIGNAR");consignar.setBounds(250,200,120,30);
  8. 8. add(consignar);consignar.addActionListener(this);//Boton De Retirarretirar=new JButton("RETIRAR");retirar.setBounds(250,300,120,30);add(retirar);retirar.addActionListener(this);//Boton De Salirsalir=new JButton("SALIR");salir.setBounds(250,400,120,30);add(salir);salir.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource()==saldo) {this.setVisible(false);Consulta_Saldo ventana=new Consulta_Saldo();ventana.setBounds(0,0,500,700);ventana.setVisible(true);ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}if (e.getSource()==consignar) {this.setVisible(false);Consulta_Consignar ventana=new Consulta_Consignar();ventana.setBounds(0,0,500,700);ventana.setVisible(true);
  9. 9. ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}if (e.getSource()==retirar) {this.setVisible(false);Retirar ventana=new Retirar();ventana.setBounds(0,0,500,600);ventana.setVisible(true);ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}if (e.getSource()==salir) {System.exit(0);}}public static void main(String[] args){Cajero ventana=new Cajero();ventana.setBounds(0,0,500,500);ventana.setVisible(true);ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}//Clase Consulta_SaldoclassConsulta_SaldoextendsJFrameimplementsActionListener{privateJButtoncta_ahorro,cta_corriente;public Consulta_Saldo(){setLayout(null);
  10. 10. //Boton Cuenta De Ahorroscta_ahorro=new JButton("CUENTA DE AHORROS");cta_ahorro.setBounds(250,200,200,30);add(cta_ahorro);cta_ahorro.addActionListener(this);//Boton Cuenta Corrientecta_corriente=new JButton("CUENTA CORRIENTE");cta_corriente.setBounds(250,250,200,30);add(cta_corriente);cta_corriente.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource()==cta_ahorro) {this.setVisible(false);}if (e.getSource()==cta_corriente) {this.setVisible(false);}}}//Clase Consulta_ConsigarclassConsulta_ConsignarextendsJFrameimplementsActionListener{privateJButtoncta_ahorro,cta_corriente;publicConsulta_Consignar(){
  11. 11. setLayout(null);//Boton Cuenta De Ahorroscta_ahorro=new JButton("CUENTA DE AHORROS");cta_ahorro.setBounds(250,200,200,30);add(cta_ahorro);cta_ahorro.addActionListener(this);//Boton Cuenta Corrientecta_corriente=new JButton("CUENTA CORRIENTE");cta_corriente.setBounds(250,250,200,30);add(cta_corriente);cta_corriente.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource()==cta_ahorro) {this.setVisible(false);}if (e.getSource()==cta_corriente) {this.setVisible(false);}}}//CLASE DE RETIRARclass Retirar extends JFrame implements ActionListener{private JButton boton1,boton2,boton3,boton4,boton5,boton6,boton7;
  12. 12. public Retirar(){setLayout(null);//Boton1boton1=new JButton("10.000");boton1.setBounds(100,100,100,30);add(boton1);boton1.addActionListener(this);//Boton2boton2=new JButton("20.000");boton2.setBounds(300,100,100,30);add(boton2);boton2.addActionListener(this);//Boton3boton3=new JButton("40.000");boton3.setBounds(100,230,100,30);add(boton3);boton3.addActionListener(this);//Boton4boton4=new JButton("100.000");boton4.setBounds(300,230,100,30);add(boton4);boton4.addActionListener(this);//Boton5boton5=new JButton("200.000");boton5.setBounds(100,360,100,30);add(boton5);
  13. 13. boton5.addActionListener(this);//Boton6boton6=new JButton("300.000");boton6.setBounds(300,360,100,30);add(boton6);boton6.addActionListener(this);//Boton7boton7=new JButton("400.000");boton7.setBounds(200,490,100,30);add(boton7);boton7.addActionListener(this);}public void actionPerformed(ActionEvent e) {if (e.getSource()==boton1) {this.setVisible(false);}if (e.getSource()==boton2) {this.setVisible(false);}if (e.getSource()==boton3) {this.setVisible(false);}if (e.getSource()==boton4) {this.setVisible(false);}
  14. 14. if (e.getSource()==boton5) {this.setVisible(false);}if (e.getSource()==boton6) {this.setVisible(false);}if (e.getSource()==boton7) {this.setVisible(false);}}}

×