完成一个按钮的事件处理程序,实现功能自拟,例如:改变窗口的背景颜色,改变按钮的位置等等.
import java.awt.Color;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Myevent implements ActionListener { JFrame f; JPanel p; JLabel l; JButton b; public Myevent() { f = new JFrame(); p = new JPanel(); l = new JLabel("杨浩亮"); b = new JButton("确定"); b.addActionListener(this); p.add(l); p.add(b); f.add(p); f.setSize(300,250); f.setVisible(true); } public static void main(String[] args) { new Myevent(); } public void actionPerformed(ActionEvent args) { p.setBackground(Color.pink); } }