JAVA事件处理的问题

来源:百度知道 编辑:UC知道 时间:2024/09/20 07:34:32
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class ButtonFrame extends Frame implements (1) {
Button btn=new Button("确认");
Label lb=new Label(" ");
TextField txt=new TextField(10);

ButtonFrame() {
super("实例10-2");
setLayout(new FlowLayout());
setBackground(Color.blue);
setSize(200,100);
lb.setForeground(Color.red);
(2) ;//给按钮注册动作监听器
add(txt);
add(btn);
add(lb);
setVisible(true);
}

//对点击“确认”按钮所做的事件处理
public void (3) (ActionEvent e) {
(4) ;
}

}

public class TestButtonFrame{
public static void main(String[] args) {
ButtonFrame buttonFrame=new

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;

class ButtonFrame extends Frame implements ActionListener{
Button btn=new Button("确认");
Label lb=new Label(" ");
TextField txt=new TextField(10);

ButtonFrame() {
super("实例10-2");
addWindowListener(new WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
setLayout(new FlowLayout());
setBackground(Color.blue);
setSize(200,100);
lb.setForeground(Color.red);
btn.addActionListener(this);//给按钮注册动作监听器
add(txt);
add(btn);
add(lb);
setVisible(true);
}

//对点击“确认”按钮所做的事件处理
//比如在TextField中输入a,在按钮右边显示a
public void actionPerformed (ActionEvent e) {
lb.setTe