| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 829 人关注过本帖
标题:小弟有难请教
只看楼主 加入收藏
aa2029
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-12-30
收藏
 问题点数:0 回复次数:12 
小弟有难请教

我写了个java 小程序.是一个表单注册的程序.将用户填写的信息提交..程序编译没有错误.执行也没有错误.就是在提交的时候出现了异常...我不知道是什么原因。.向高手请教哈子....下面是我的程序.
package chu;
import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Frame1 extends JFrame {
public Frame1() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 20));
jLabel1.setText("学员信息表");
jLabel1.setBounds(new Rectangle(154, 14, 111, 42));
jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
jPanel1.setBounds(new Rectangle(44, 57, 339, 377));
jPanel1.setLayout(null);
jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel2.setText("用户:");
jLabel2.setBounds(new Rectangle(19, 19, 86, 32));
jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel3.setText("密码:");
jLabel3.setBounds(new Rectangle(17, 74, 92, 29));
jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel4.setText("年龄:");
jLabel4.setBounds(new Rectangle(15, 157, 73, 35));
jLabel5.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel5.setText("爱好:");
jLabel5.setBounds(new Rectangle(15, 206, 65, 32));
jLabel6.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel6.setText("城市:");
jLabel6.setBounds(new Rectangle(18, 262, 61, 30));
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(100, 25, 146, 20));
jPasswordField1.setText("jPasswordField1");
jPasswordField1.setBounds(new Rectangle(102, 81, 144, 20));
jCheckBox1.setText("上网");
jCheckBox1.setBounds(new Rectangle(100, 214, 72, 27));
jCheckBox2.setText("大架");
jCheckBox2.setBounds(new Rectangle(184, 212, 53, 27));
jCheckBox3.setText("游泳");
jCheckBox3.setBounds(new Rectangle(260, 212, 61, 27));
jScrollPane1.setBounds(new Rectangle(102, 259, 199, 94));
jList1.setBounds(new Rectangle(104, 263, 194, 79));
jButton1.setBounds(new Rectangle(52, 460, 120, 46));
jButton1.setText("确定");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(274, 467, 107, 38));
jButton2.setText("取消");
jComboBox1.setBounds(new Rectangle(102, 159, 144, 33));
jLabel7.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel7.setText("性别:");
jLabel7.setBounds(new Rectangle(16, 119, 65, 32));

jRadioButton1.setText("男");
jRadioButton1.setBounds(new Rectangle(103, 118, 64, 22));
jRadioButton2.setText("女");
jRadioButton2.setBounds(new Rectangle(181, 121, 58, 22));
this.getContentPane().add(jLabel1);
this.getContentPane().add(jPanel1);
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
jPanel1.add(jLabel2);
jPanel1.add(jLabel3);
jPanel1.add(jLabel6);
jPanel1.add(jTextField1);
jPanel1.add(jPasswordField1);
jPanel1.add(jScrollPane1);
jPanel1.add(jComboBox1);
jPanel1.add(jCheckBox1);
jPanel1.add(jCheckBox2);
jPanel1.add(jCheckBox3);
jPanel1.add(jLabel5);
jPanel1.add(jLabel7);
jPanel1.add(jLabel4);
jPanel1.add(jRadioButton1);
jPanel1.add(jRadioButton2);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton1);
jScrollPane1.getViewport().add(jList1);
}
public static void main(String[] args) {
Frame1 frame1 = new Frame1();
frame1.setSize(600,600);
frame1.show();

}
JLabel jLabel1 = new JLabel();
JPanel jPanel1 = new JPanel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();
JCheckBox chu[]=new JCheckBox[3];
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
JScrollPane jScrollPane1 = new JScrollPane();
String bb[]={"北京","上海","武汉","孝感","深圳"};
JList jList1 = new JList(bb);
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
String aa[]={"20","21","22"};
JComboBox jComboBox1 = new JComboBox(aa);
JLabel jLabel7 = new JLabel();
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
ButtonGroup buttonGroup1 = new ButtonGroup();
public void jButton1_actionPerformed(ActionEvent e)
{

String name=this.jTextField1.getText();
String pwd=this.jPasswordField1.getText();
String sex="";
if(this.jRadioButton1.isSelected())
{
sex="男";
}
else
sex=" 女";
String age=this.jComboBox1.getSelectedItem().toString();
String like="";
for(int i=0;i<=chu.length;i++)
{
if(chu[i].isSelected())
{
like=like+","+chu[i].getText();

}
}

String city=this.jList1.getSelectedValue().toString();

String art="用户"+name+"\n"+"密码"+pwd+"\n"+"性别"+sex+"\n"+"年龄"+age+"\n"+"爱好"+like+"\n"+"城市"+city;
JOptionPane.showMessageDialog(null,art);
}
}
class Frame1_jButton1_actionAdapter implements ActionListener
{
private Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
package chu;

import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Frame1 extends JFrame {
public Frame1() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

private void jbInit() throws Exception {
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 20));
jLabel1.setText("学员信息表");
jLabel1.setBounds(new Rectangle(154, 14, 111, 42));
jPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
jPanel1.setBounds(new Rectangle(44, 57, 339, 377));
jPanel1.setLayout(null);
jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel2.setText("用户:");
jLabel2.setBounds(new Rectangle(19, 19, 86, 32));
jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel3.setText("密码:");
jLabel3.setBounds(new Rectangle(17, 74, 92, 29));
jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel4.setText("年龄:");
jLabel4.setBounds(new Rectangle(15, 157, 73, 35));
jLabel5.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel5.setText("爱好:");
jLabel5.setBounds(new Rectangle(15, 206, 65, 32));
jLabel6.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel6.setText("城市:");
jLabel6.setBounds(new Rectangle(18, 262, 61, 30));
jTextField1.setText("jTextField1");
jTextField1.setBounds(new Rectangle(100, 25, 146, 20));
jPasswordField1.setText("jPasswordField1");
jPasswordField1.setBounds(new Rectangle(102, 81, 144, 20));
jCheckBox1.setText("上网");
jCheckBox1.setBounds(new Rectangle(100, 214, 72, 27));
jCheckBox2.setText("大架");
jCheckBox2.setBounds(new Rectangle(184, 212, 53, 27));
jCheckBox3.setText("游泳");
jCheckBox3.setBounds(new Rectangle(260, 212, 61, 27));
jScrollPane1.setBounds(new Rectangle(102, 259, 199, 94));
jList1.setBounds(new Rectangle(104, 263, 194, 79));
jButton1.setBounds(new Rectangle(52, 460, 120, 46));
jButton1.setText("确定");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(274, 467, 107, 38));
jButton2.setText("取消");
jComboBox1.setBounds(new Rectangle(102, 159, 144, 33));
jLabel7.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
jLabel7.setText("性别:");
jLabel7.setBounds(new Rectangle(16, 119, 65, 32));

jRadioButton1.setText("男");
jRadioButton1.setBounds(new Rectangle(103, 118, 64, 22));
jRadioButton2.setText("女");
jRadioButton2.setBounds(new Rectangle(181, 121, 58, 22));
this.getContentPane().add(jLabel1);
this.getContentPane().add(jPanel1);
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
jPanel1.add(jLabel2);
jPanel1.add(jLabel3);
jPanel1.add(jLabel6);
jPanel1.add(jTextField1);
jPanel1.add(jPasswordField1);
jPanel1.add(jScrollPane1);
jPanel1.add(jComboBox1);
jPanel1.add(jCheckBox1);
jPanel1.add(jCheckBox2);
jPanel1.add(jCheckBox3);
jPanel1.add(jLabel5);
jPanel1.add(jLabel7);
jPanel1.add(jLabel4);
jPanel1.add(jRadioButton1);
jPanel1.add(jRadioButton2);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton1);
jScrollPane1.getViewport().add(jList1);
}

public static void main(String[] args) {
Frame1 frame1 = new Frame1();
frame1.setSize(600,600);
frame1.show();

}

JLabel jLabel1 = new JLabel();
JPanel jPanel1 = new JPanel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JTextField jTextField1 = new JTextField();
JPasswordField jPasswordField1 = new JPasswordField();

JCheckBox chu[]=new JCheckBox[3];
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();

JScrollPane jScrollPane1 = new JScrollPane();
String bb[]={"北京","上海","武汉","孝感","深圳"};
JList jList1 = new JList(bb);
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
String aa[]={"20","21","22"};
JComboBox jComboBox1 = new JComboBox(aa);
JLabel jLabel7 = new JLabel();

JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
ButtonGroup buttonGroup1 = new ButtonGroup();
public void jButton1_actionPerformed(ActionEvent e)
{

String name=this.jTextField1.getText();
String pwd=this.jPasswordField1.getText();
String sex="";
if(this.jRadioButton1.isSelected())
{
sex="男";
}
else
sex=" 女";

String age=this.jComboBox1.getSelectedItem().toString();

String like="";
for(int i=0;i<=chu.length;i++)
{
if(chu[i].isSelected())
{
like=like+","+chu[i].getText();

}
}

String city=this.jList1.getSelectedValue().toString();

String art="用户"+name+"\n"+"密码"+pwd+"\n"+"性别"+sex+"\n"+"年龄"+age+"\n"+"爱好"+like+"\n"+"城市"+city;
JOptionPane.showMessageDialog(null,art);



}
}


class Frame1_jButton1_actionAdapter implements ActionListener
{
private Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}

搜索更多相关主题的帖子: java 表单 package import 
2007-01-02 22:51
aa2029
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-12-30
收藏
得分:0 
补充说明

刚才不把代码复制了两次....不好意思哈..

2007-01-02 22:53
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
异常代码帖出来

可惜不是你,陪我到最后
2007-01-02 22:57
弱智抓蛙男
Rank: 1
等 级:新手上路
帖 子:264
专家分:0
注 册:2006-11-24
收藏
得分:0 

长阿~~~~~~
没看完
不过我有个疑问:那一串改为import javax.swing.*不行么?
这样写好累啊。。。。

2007-01-02 22:58
aa2029
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-12-30
收藏
得分:0 
   我这样写是一是为了让人看的更清楚.二是为了提高程序的运行速度...我发的是两个一样的饿.你从中间截断就ok了...
2007-01-02 23:02
弱智抓蛙男
Rank: 1
等 级:新手上路
帖 子:264
专家分:0
注 册:2006-11-24
收藏
得分:0 

老千要异常代码 你快贴出来
他机子说不定是垃圾 运行不了java文件

2007-01-02 23:05
aa2029
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-12-30
收藏
得分:0 
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at chu.Frame1.jButton1_actionPerformed(Frame1.java:159)
at chu.Frame1_jButton1_actionAdapter.actionPerformed(Frame1.java:186)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at chu.Frame1.jButton1_actionPerformed(Frame1.java:159)
at chu.Frame1_jButton1_actionAdapter.actionPerformed(Frame1.java:186)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
2007-01-02 23:12
弱智抓蛙男
Rank: 1
等 级:新手上路
帖 子:264
专家分:0
注 册:2006-11-24
收藏
得分:0 
NullPointerException
我不知道出在哪里
2007-01-02 23:17
aa2029
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-12-30
收藏
得分:0 

冰哥帮我找出问题来了吗?
我发现:
我的代码中的那个爱好的植取不出来!
你帮我看看!
可能就是那里出现了问题!

2007-01-02 23:38
开心一科
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2006-10-5
收藏
得分:0 
JCheckBox []chu = new JCheckBox[3];
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
后面三个JCheckBox 没在chu中巴
那后怎么用chu判断选中了哪个
还有后面,条件i<=chu.length 把等号去掉

2007-01-02 23:50
快速回复:小弟有难请教
数据加载中...
 
   



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

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