问答题
阅读下列程序,写出程序的功能。
public class C34 extends Applet
{
static JFrame myWin;
static SetBG setbg=new SetBG( );
static JButton button;
public void init( )
{
myWin=new JFrame("C34");
myWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWin.setBounds(200,300,300,400);
myWin.setLayout(new FJowLayout( ));
Container con=myWin.getContentPane( );
con.setBackground(Color.blue);
button=new JButton("OK");
button.addActionListener(setbg);
myWin.add (button);
myWin.setVisible(true);
}
}
class SetBG implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Container con=C34.myWin.getContentPane( );
if(con.getBackground( )==Color.blue)
con.setBackground (Color.green);
else
con.setBackgroud (Color.blue);
}
}
【参考答案】
程序的功能:小应用程序启动后,在窗口中有一个按钮,反复点击按钮,可使窗口背景颜色蓝绿交替变化。[考点] 窗口
[......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)