事件:点击按钮,改变背景色时间:2022-03-03 12:49:41 import java.awt. * ; import java.awt.event. * ; import javax.swing. * ; public class UseActionListener extends JFrame ... { Button OK; public UseActionListener() ...{ super("UseListener"); OK = new Button("change background"); MyListener listen = new MyListener(); OK.addActionListener(listen); this.getContentPane().add(OK); this.setSize(200,200); this.setVisible(true); } class MyListener implements ActionListener ...{ public void actionPerformed(ActionEvent action) ...{ //handle the event if(OK.getBackground().equals(Color.blue)) OK.setBackground(Color.orange); else OK.setBackground(Color.blue); } } public static void main(String args[])...{ new UseActionListener(); } }