事件处理

package Demo;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
	public class chuangkou implements ActionListener{
	   JFrame f;
	   JPanel p;
	   JButton b;
	   JLabel l;
	public chuangkou() {
	    f=new JFrame();
	    p=new JPanel(null);
	    b=new JButton("确定");
	    l=new JLabel();
	    b.addActionListener(this);
	    f.add(p);
	    p.add(b);
	    p.add(l);
	    f.setVisible(true);
	    f.setSize(400,400);
	    l.setBounds(50,120,50,50);
	    b.setBounds(150,150,80,80);
	}
	    public static void main(String[] args) {
	       new chuangkou();
	}
	    public void actionPerformed(ActionEvent e) {
	        p.setBackground(Color.pink);
	        l.setText("嘿嘿嘿嘿嘿");
	        b.setBounds(250,50,80,80);
	    }
}


posted @ 2019-05-08 11:57  Lowice  阅读(110)  评论(0编辑  收藏  举报