Advertisement
Guest User

codigo

a guest
May 6th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3.  
  4. @SuppressWarnings("serial")
  5. public class Ejvent extends Frame implements WindowListener , ActionListener , KeyListener{
  6.         Button b1,b2;
  7.         Label lb1,lb2;
  8.         List l1;
  9.         Choice ch1;
  10.         TextField tf1,tf2;
  11.  
  12.         public Ejvent(){
  13.                 setLayout(null);
  14.                 setTitle("Ejemplo Ventana 1");
  15.                
  16.  
  17.                 l1=new List(4,true);
  18.                 l1.setBounds(20,200,100,100);
  19.                 l1.add("Audi");
  20.                 l1.add("BMW");
  21.                 l1.add("Chevrolet");
  22.                 l1.add("Mercedez Benz");
  23.                 l1.add("Toyota");
  24.                 add(l1);
  25.  
  26.                 ch1=new Choice();
  27.                 ch1.setBounds(150,200,130,15);
  28.                 ch1.add("Audi");
  29.                 ch1.add("BMW");
  30.                 ch1.add("Chevrolet");
  31.                 ch1.add("Mercedes benz");
  32.                 ch1.add("Toyota");
  33.                 add(ch1);
  34.  
  35.                 lb1=new Label("Codigo:");
  36.                 lb1.setBounds(20,50,100,20);
  37.                 add(lb1);
  38.                
  39.                 lb2=new Label();
  40.                 lb2.setBounds(250,350,100,20);
  41.                 add(lb2);
  42.  
  43.                 tf1=new TextField();
  44.                 tf1.setBounds(125,50,50,20);
  45.                 add(tf1);
  46.                
  47.                
  48.                 tf2=new TextField();
  49.                 tf2.setBounds(250,300,100,20);
  50.                 add(tf2);
  51.                
  52.  
  53.                 b1=new Button("Salir");
  54.                 b1.setBounds(250,150,100,40);
  55.                 add(b1);
  56.                
  57.                 b2=new Button("Mostrar");
  58.                 b2.setBounds(100,150,100,40);
  59.                 add(b2);
  60.  
  61.                 b1.addActionListener(this);
  62.                 b2.addActionListener(this);
  63.                 addWindowListener(this);
  64.                 tf1.addKeyListener(this);
  65.  
  66. }
  67.  
  68.         public static void main(String[] args) {
  69.                 Ejvent ev = new Ejvent();
  70.                 ev.setSize(500,400);
  71.                 ev.setVisible(true);
  72.                 ev.setLocationRelativeTo(null);
  73.  
  74. }
  75.  
  76.         public void windowOpened(WindowEvent e) {
  77.  
  78. }
  79.  
  80.        
  81.         public void windowClosing(WindowEvent e) {
  82.                 System.exit(0);
  83. }
  84.  
  85.        
  86.         public void windowClosed(WindowEvent e) {
  87.  
  88. }
  89.  
  90.        
  91.         public void windowIconified(WindowEvent e) {
  92.  
  93. }
  94.  
  95.        
  96.         public void windowDeiconified(WindowEvent e) {
  97.  
  98. }
  99.  
  100.        
  101.         public void windowActivated(WindowEvent e) {
  102.  
  103. }
  104.  
  105.      
  106.         public void windowDeactivated(WindowEvent e) {
  107.  
  108.  }
  109.  
  110.        
  111.         public void actionPerformed(ActionEvent ae) {
  112.                 if (ae.getSource()==b2){
  113.                         String s = tf1.getText();
  114.                         tf2.setText(s);
  115.                         lb2.setText(s);
  116.                        
  117.                 }
  118.                 if (ae.getSource()==b1){
  119.                         System.exit(0);
  120.                 }
  121.                
  122.         }
  123.  
  124.      
  125.         public void keyPressed(KeyEvent arg0) {
  126.                
  127.         }
  128.  
  129.        
  130.         public void keyReleased(KeyEvent arg0) {
  131.                
  132.         }
  133.  
  134.        
  135.         public void keyTyped(KeyEvent e) {
  136.                 if (tf1.getText().length()==4) {
  137.                         e.consume();
  138.                 }
  139.                 char c = e.getKeyChar();
  140.                 if (!(Character.isDigit(c) ||
  141.                 (c == KeyEvent.VK_BACK_SPACE) ||
  142.                 (c == KeyEvent.VK_DELETE))) {
  143.                 getToolkit().beep();
  144.                 e.consume();
  145.                 }
  146.                 }
  147.                 ;
  148.        
  149.                
  150.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement