完成一个按钮的事件处理程序,实现功能自拟,例如:改变窗口的背景颜色,改变按钮的位置等等。
package qwe;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.
;
public class Ewq implements ActionListener {
Frame f;
Panel p;
Button b;
public Ewq() {
f=new Frame();
p=new Panel();
b=new Button("按钮");
b.addActionListener(this);
f.setSize(400,400);
f.add(p);
p.add(b);
f.setVisible(true);
}
public static void main(String[] args) {
new Ewq();
}
public void actionPerformed(ActionEvent e) {
b.setBackground(Color.blue);
p.setBackground(Color.red);
}
}