| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 610 人关注过本帖
标题:这个问题太怪了,请帮帮我吧.
只看楼主 加入收藏
qvbhsskg
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2005-4-28
收藏
 问题点数:0 回复次数:4 
这个问题太怪了,请帮帮我吧.
这个问题太怪了,请帮帮我吧. 是一个选择框的程序:编译通过了,运行时出现: 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
波荔南潜
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2005-9-8
收藏
得分:0 
这可能是路径的问题

2005-09-25 20:55
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 
构造器没有返回值这一说,所以不能写成void combobox()

相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2005-09-25 21:13
kuixingzai
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2005-5-16
收藏
得分:0 
对,构件无返回值

菜鸟飞,菜鸟飞,菜鸟高高飞!
2005-09-26 09:13
宇扬
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-9-26
收藏
得分:0 

哈哈.兄弟你有福了,我给你问了好多人才知道结果是哪里错了,自己看看吧 还请以后把代码写规范点,要不很难看,哈哈 import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; class combobox extends JFrame implements ItemListener { JFrame frame; JComboBox choice1,choice2; JTextField text1,text2; JPanel panel1,panel2; combobox(){ frame=new JFrame("jcomboBox演示窗口"); panel1=new JPanel(); panel2=new JPanel(); choice1=new JComboBox(); choice2=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){text2.setText("北京");} else if(choice2.getSelectedIndex()==2){text2.setText("上海");} else if(choice2.getSelectedIndex()==3){text2.setText("天津");} else if(choice2.getSelectedIndex()==4){text2.setText("四川");} } } public static void main(String args[]){ new combobox(); } }

2005-09-26 19:10
快速回复:这个问题太怪了,请帮帮我吧.
数据加载中...
 
   



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

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