我写了个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);
}
}