import java.awt.*;
import java.awt.event.*;
public class app16_3 extends Frame implements ActionListener
{
static app16_3 frm=new app16_3();
static Button btn1=new Button("yellow");
static Button btn2=new Button("green");
static Button btn3=new Button("exit");
public static void main(String args[]){
btn1.addActionListener(frm);
btn2.addActionListener(frm);
btn3.addActionListener(frm);
frm.setTitle("Action Event");
frm.setLayout(new FlowLayout(FlowLayout.CENTER));
frm.setSize(200,150);
frm.add(btn1);
frm.add(btn2);
frm.add(btn3);
frm.setVisible(true);
}
public void actionPerformed(ActionEvent e){
Button btn=(Button)e.getSource();
if(btn==btn1)
frm.setBackground(Color.yellow);
else if(btn==btn2)
frm.setBackground(Color.green);
else
System.exit(0);
}
}
窗口关闭事件
最新推荐文章于 2022-05-19 11:46:44 发布