• 完成一个按钮的事件处理程序,实现功能自拟,例如:改变窗口的背景颜色,改变按钮的位置等等。
package win;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class work implements ActionListener {
    JFrame f;
    JPanel p;
    JButton b;
    JLabel l;
    public work() {
        f = new JFrame("lN3");
        p = new JPanel();
        b = new JButton("599");
        b.setBounds(80, 50, 80, 50);
        b.addActionListener(this);
        l = new JLabel();
        l.setBounds(100,200,50,100);
        p.add(b);
        p.add(l);
        p.setBackground(Color.pink);
        f.add(p);
        f.setVisible(true);
        f.setSize(400, 400);
    }


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


public void actionPerformed(ActionEvent e) {
    p.setBackground(Color.orange);
    b.setBounds(60, 70, 100, 20);
    l.setText("Faithful to your heart.");
    l.setBounds(150, 100, 150,100);
}
}