Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- @SuppressWarnings("serial")
- public class Ejvent extends Frame implements WindowListener , ActionListener , KeyListener{
- Button b1,b2;
- Label lb1,lb2;
- List l1;
- Choice ch1;
- TextField tf1,tf2;
- public Ejvent(){
- setLayout(null);
- setTitle("Ejemplo Ventana 1");
- l1=new List(4,true);
- l1.setBounds(20,200,100,100);
- l1.add("Audi");
- l1.add("BMW");
- l1.add("Chevrolet");
- l1.add("Mercedez Benz");
- l1.add("Toyota");
- add(l1);
- ch1=new Choice();
- ch1.setBounds(150,200,130,15);
- ch1.add("Audi");
- ch1.add("BMW");
- ch1.add("Chevrolet");
- ch1.add("Mercedes benz");
- ch1.add("Toyota");
- add(ch1);
- lb1=new Label("Codigo:");
- lb1.setBounds(20,50,100,20);
- add(lb1);
- lb2=new Label();
- lb2.setBounds(250,350,100,20);
- add(lb2);
- tf1=new TextField();
- tf1.setBounds(125,50,50,20);
- add(tf1);
- tf2=new TextField();
- tf2.setBounds(250,300,100,20);
- add(tf2);
- b1=new Button("Salir");
- b1.setBounds(250,150,100,40);
- add(b1);
- b2=new Button("Mostrar");
- b2.setBounds(100,150,100,40);
- add(b2);
- b1.addActionListener(this);
- b2.addActionListener(this);
- addWindowListener(this);
- tf1.addKeyListener(this);
- }
- public static void main(String[] args) {
- Ejvent ev = new Ejvent();
- ev.setSize(500,400);
- ev.setVisible(true);
- ev.setLocationRelativeTo(null);
- }
- public void windowOpened(WindowEvent e) {
- }
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- public void windowClosed(WindowEvent e) {
- }
- public void windowIconified(WindowEvent e) {
- }
- public void windowDeiconified(WindowEvent e) {
- }
- public void windowActivated(WindowEvent e) {
- }
- public void windowDeactivated(WindowEvent e) {
- }
- public void actionPerformed(ActionEvent ae) {
- if (ae.getSource()==b2){
- String s = tf1.getText();
- tf2.setText(s);
- lb2.setText(s);
- }
- if (ae.getSource()==b1){
- System.exit(0);
- }
- }
- public void keyPressed(KeyEvent arg0) {
- }
- public void keyReleased(KeyEvent arg0) {
- }
- public void keyTyped(KeyEvent e) {
- if (tf1.getText().length()==4) {
- e.consume();
- }
- char c = e.getKeyChar();
- if (!(Character.isDigit(c) ||
- (c == KeyEvent.VK_BACK_SPACE) ||
- (c == KeyEvent.VK_DELETE))) {
- getToolkit().beep();
- e.consume();
- }
- }
- ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement