事件处理程序

package 事件处理;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Xiu implements ActionListener {
    JFrame f;
    JPanel p;
    JButton b;
    public Xiu() {
        f=new JFrame();
        p=new JPanel();
        b=new JButton("单击");
        b.addActionListener(this);
        f.setSize(400,450);
        f.add(p);
        p.add(b);
        f.setVisible(true);
    }

    public static void main(String[] args) {
        new Xiu();

    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        p.setBackground(Color.BLUE);
    }

}

  

posted @ 2019-07-05 11:59  ANTl  阅读(144)  评论(0编辑  收藏  举报