import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class A extends Applet implements ActionListener{
String msg="";
Label lb=new Label(" 请问母亲节在那个月份?");
TextField tf=new TextField(30);
public void init(){
add(lb);
Button a=new Button("1");
Button b=new Button("3");
Button c=new Button("5");
Button d=new Button("7");
add(a);
add(b);
add(c);
add(d);
a.addActionListener(this);
b.addActionListener(this);
c.addActionListener(this);
d.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
String str=e.getActionCommand();
if (str=="5"){
msg="你是个好孩子";
}
else{
msg="你是个不孝子";
}
repaint();
}
public void paint(Graphics g){
g.drawString(msg,6,100);
}
}
按键监听
最新推荐文章于 2022-10-10 11:19:34 发布