事件处理

完成一个按钮的事件处理程序,实现功能自拟,例如:改变窗口的背景颜色,改变按钮的位置等等

 

package ccc;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class window implements ActionListener{
JFrame f;
JButton s;
JLabel p;
JPanel a;
public window() {
f=new JFrame();
s=new JButton("点击");
p=new JLabel();
a=new JPanel();
s.addActionListener(this);
f.setSize(800,600);
f.setVisible(true);
f.add(a);
a.add(s);
a.add(p);
}
public static void main(String[]arge){
new window();
}
public void actionPerformed(ActionEvent e) {
a.setBackground(Color.yellow);
}
}

 

 

posted @ 2019-05-12 09:56  阿铭。  阅读(80)  评论(0编辑  收藏  举报