阅读下程序,写出程序功能。
import java. awt.*;
import java. applet.*;
import javax. swing.*;
import java. awt. event. * ;
public class C3402 extends Applet
static JFrame myWin;
static SetBG setbg=new SetBG();
static JButton button;
public void init()
myWin=new JFrame("C3402");
myWin. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWin. setBounds(100,200,300,400);
myWin. setLayout(new FlowLayout();
Container con=myWin. getContentPane();
con. setBackground(Color. red);
button=new JButton("OK");
button. addActionListener(setbg);
myWin.add(button);
myWin.setVisible(true);
class SetBG implements ActionListener
public void actionPerformed(ActionEvent e)
Container con=C3402. myWin. getContentPane();
if(con. getBackground()==Color. red)
con. setBackground(Color. green);
else
con.setBackground(Color.red);
参考答案:程序功能:小应用程序启动后,在窗口中有一个按钮,反复单击按钮,可使窗口背景色红绿交替变化。