问答题
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
源程序文件清单如下:
import java.awt.*;
import java.awt.event.*;
public class ex11_2 extends Frame implements ActionListener, ItemListener
{
private Label 1;
private String str="label";
private Choice choice11_2;
public static void main(String[] arg)
{
new ex11_2();
}
ex11_2 ()
{
setLayout (______);
choice11_2 = new Choice();
choice11_2.addItem("item1");
choice11_2.addItem("item2");choice11_2.______;
add(choice11_2);
l=new Label(str);
add(l);
Button exit11_2 = new Button("exit");
exit11_2.addActionListener(this);
add(exit11_2);
for(int i=0; i<3; i++)
add(new Button("button" + i));
setSize(300,300);
pack();
show();
}
public void actionPerformed(ActionEvent event)
{
if (event.getActionCommand ( ). equals ( "exit" ) )
{
System.exit(0);
}
}
public void itemStateChanged(ItemEvent event
{
str=choice11_2.getSelectedItem();
l.setText(str);
}
}