事件处理程序

package ddd;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Ban implements ActionListener{
	JFrame f;
	JPanel p;
	JButton b;
    public Ban(){
	    f=new JFrame();
	    p=new JPanel();
	    b=new JButton("变色");
	    b.addActionListener(this);
	    p.add(b);
	    f.add(p);  
	    f.setSize(300,400);
	    f.setVisible(true);	    	
    }
	public static void main(String[] args) {
		new Ban();		
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		p.setBackground(Color.blue);		
	}
}

posted on 2019-05-09 22:51  无聊的ak  阅读(99)  评论(0)    收藏  举报

导航