标题:这个问题太怪了,请帮帮我吧.
取消只看楼主
qvbhsskg
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2005-4-28
 问题点数:0 回复次数:0 
这个问题太怪了,请帮帮我吧.
这个问题太怪了,请帮帮我吧. 是一个选择框的程序:编译通过了,运行时出现: Exception in thread "main" java.lang.NullPointerException at combobox.combobox(ll.java:18) at ll.main(ll.java:56) 源程序如下,请帮帮我啊. import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; class combobox implements ItemListener {JFrame frame; JComboBox choice1,choice2; JTextField text1,text2; JPanel panel1,panel2; void combobox() {frame=new JFrame("jcomboBox演示窗口"); panel1=new JPanel(); panel2=new JPanel(); choice1=new JComboBox(); choice1=new JComboBox(); text1=new JTextField(10); text2=new JTextField(10); choice1.addItem("音乐");choice2.addItem("重庆"); choice1.addItem("新闻");choice2.addItem("北京"); choice1.addItem("体育");choice2.addItem("上海"); choice1.addItem("生活");choice2.addItem("天津"); choice1.addItem("教育");choice2.addItem("四川"); Container con=frame.getContentPane(); con.setLayout(new BoxLayout(con,BoxLayout.Y_AXIS)); panel1.add(choice1);panel1.add(choice2); panel2.add(text1);panel2.add(text2); con.add(panel1);con.add(panel2); choice1.addItemListener(this); choice2.addItemListener(this); frame.setSize(600,600); frame.setVisible(true);frame.show(); } public void itemStateChanged(ItemEvent e) {if(e.getItemSelectable()==choice1) {if(choice1.getSelectedIndex()==0) {text1.setText("音乐");} else if(choice1.getSelectedIndex()==1) {text1.setText("新闻");} else if(choice1.getSelectedIndex()==2){text1.setText("体育");} else if(choice1.getSelectedIndex()==3){text1.setText("生活");} else if(choice1.getSelectedIndex()==4){text1.setText("教育");} } else if(e.getItemSelectable()==choice2) { if(choice2.getSelectedIndex()==0) {text1.setText("重庆");} else if(choice2.getSelectedIndex()==1){text1.setText("北京");} else if(choice2.getSelectedIndex()==2){text1.setText("上海");} else if(choice2.getSelectedIndex()==3){text1.setText("天津");} else if(choice2.getSelectedIndex()==4){text1.setText("四川");} } }} public class ll{ public static void main(String args[]) {combobox kk=new combobox(); kk.combobox();} }
搜索更多相关主题的帖子: thread frame import 源程序 
2005-09-23 22:01



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




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

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