标题:[求助]初学者的小问题
取消只看楼主
mctracy84082
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-11-27
 问题点数:0 回复次数:0 
[求助]初学者的小问题
import java.awt.*;
import java.awt.event.*;
class WindowChoice extends Frame implements ItemListener,ActionListener
{
Choice choice;
TextField text;
TextArea area;
Button ad,del;
WindowChoice()
{
setLayout(new FlowLayout());
choice=new Choice();
text=new TextField(8);
area=new TextArea(8,25);
choice.add("音乐天地");
choice.add("无数天地");
choice.add("象棋乐园");
choice.add("交友聊天");
ad.addActionListener(this);
del.addActionListener(this);
text.addActionListener(this);
choice.addItemListener(this);
add(choice);
add(del);
add(ad);
add(area);
add(text);
setSize(200,200);
setVisible(true);
validate();
}
public void itemStateChanged(ItemEvent e)
{
String name=choice.getSelectedItem();
int index=choice.getSelectedIndex();
area.setText("\n"+index+":"+name);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ad||e.getSource()==text)
{
String name=text.getText();
choice.add(name);
choice.select(name);
area.append("\n列表添加"+name);

}
else if(e.getSource()==del)
{
area.append("\n列表删除"+choice.getSelectedItem());
choice.remove(choice.getSelectedIndex());
}
}
}
public class Example6
{
public static void main(String [] args)
{
new WindowChoice();
}
}

出现Exception in thread "main" java.lang.NullPointerException
at WindowChoice.<init>(Example6.java:19)
at Example6.main(Example6.java:59)
刚开始学习java各位高手能指点一下么,感激涕零!!!!
搜索更多相关主题的帖子: Choice choice import 音乐 
2006-11-27 21:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-105773-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.740529 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved