learning java AWT EventQs

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EventQs {
    private Frame f = new Frame("event test");
    private Button ok  = new Button("confired");
    private TextField tf = new TextField(50);
    public void init(){
        ok.addActionListener(new OkListener());
        f.add(tf);
        f.add(ok, BorderLayout.SOUTH);
        f.pack();
        f.setVisible(true);
    }

    class  OkListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
            System.out.println("button be pressed");
            tf.setText("hello panzidong");

        }
    }
    public static void main(String[] args) {
        new EventQs().init();
    }
}

output:

posted @ 2019-07-30 17:21  嵌入式实操  阅读(209)  评论(0编辑  收藏  举报