如题
就是能给我一个完整的程序。。。
------解决方案--------------------
import java.awt.*;
import java.awt.event.*;
public class Tests implements ItemListener
{
Choice choice;
Frame f;
TextArea text;
public Tests()
{
f = new Frame();
choice = new Choice();
for(int i= 1;i <10;i++)
choice.add( "选项 " + i);
choice.addItemListener(this);
text = new TextArea(6,6);
f.add(text, "Center ");
f.add(choice, "North ");
f.setSize(300,300);
f.setVisible(true);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public static void main(String args[])
{
new Tests();
}
public void itemStateChanged(ItemEvent e)
{
text.append(choice.getSelectedItem() + '\n ' );
}
}
编译运行通过,参考下