首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

choice事件监听该如何写

2012-01-31 
choice事件监听该怎么写?如题就是能给我一个完整的程序。。。 [解决办法]import java.awt.*import java.awt.

choice事件监听该怎么写?
如题
就是能给我一个完整的程序。。。


[解决办法]
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 ' );
}
}

编译运行通过,参考下

热点排行
Bad Request.