改变按钮颜色的java事件
import java.awt.*;import java.awt.event.*;
public class Eventest
{
Button btn1=new Button("单击");
Frame myframe=new Frame("测试单击事件");
public void init(){
btn1.setSize(30,26);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(btn1.getBackground()==Color.red)
btn1.setBackground(Color.white);
else
btn1.setBackground(Color.red);
}
});
myframe.setBounds(300,200,200,200);
myframe.add(btn1);
myframe.setVisible(true);
}
public static void main(String[] args)
{
new Eventest().init();
}
}