Nin7a 2017-11-18 14:31 采纳率: 0%
浏览 914

这个java代码有什么问题吗,怎么报了那么多错

 package Package1;
import java.sql.*;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;


public class Register  extends JFrame{
    private JPanel contentPane;
    private JTextField textField;
    private JTextField textField_2;
    private JPasswordField passwordField;
    private JTextField textField_1;
    private JTextField textField_3;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Register frame = new Register();
                    frame.setVisible(true);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Register() throws Exception{
        super("注册界面");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 526, 432);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        textField = new JTextField();
        textField.setBounds(151, 33, 223, 24);
        contentPane.add(textField);
        textField.setColumns(10);

        JLabel label = new JLabel("用户名:");
        label.setBounds(32, 36, 72, 18);
        contentPane.add(label);

        JLabel label_1 = new JLabel("\u5BC6  \u7801\uFF1A");
        label_1.setBounds(32, 88, 72, 18);
        contentPane.add(label_1);

        JLabel label_2 = new JLabel("\u59D3  \u540D\uFF1A");
        label_2.setBounds(32, 138, 72, 18);
        contentPane.add(label_2);

        textField_2 = new JTextField();
        textField_2.setColumns(10);
        textField_2.setBounds(151, 135, 223, 24);
        contentPane.add(textField_2);

        passwordField = new JPasswordField();
        passwordField.setBounds(151, 85, 223, 24);
        contentPane.add(passwordField);

        JLabel label_3 = new JLabel("\u5B66  \u53F7\uFF1A");
        label_3.setBounds(32, 187, 72, 18);
        contentPane.add(label_3);

        textField_1 = new JTextField();
        textField_1.setColumns(10);
        textField_1.setBounds(151, 184, 223, 24);
        contentPane.add(textField_1);

        JLabel label_4 = new JLabel("\u8054\u7CFB\u65B9\u5F0F\uFF1A");
        label_4.setBounds(32, 239, 83, 18);
        contentPane.add(label_4);

        textField_3 = new JTextField();
        textField_3.setColumns(10);
        textField_3.setBounds(151, 236, 223, 24);
        contentPane.add(textField_3);
        JTextArea textArea = new JTextArea();
        textArea.setEditable(false);
        textArea.setBounds(32, 300, 113, 24);
        contentPane.add(textArea);

        JButton button = new JButton("\u5B8C\u6210\u6CE8\u518C");
        button.setBounds(185, 298, 113, 27);
        contentPane.add(button);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String passwords;//密码
                String usernames;//用户名
                String names;//姓名
                String ids;//学号
                String phones;//联系方式
                char[] pswd=passwordField.getPassword();
                passwords=String.valueOf(pswd);
                usernames=textField.getText();
                names=textField_2.getText();
                ids=textField_1.getText();
                phones=textField_3.getText();

                try {
                    Connection1 contosql = null;
                    try {
                        contosql = new Connection1();//连接数据库
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    if(passwords.equals("")||usernames.equals("")||names.equals("")||ids.equals("")||phones.equals("")) {//五个选项任意一个为空的话
                        textArea.setText("请填写完整!");
                    }
                    else {
                        PreparedStatement psql=contosql.con.prepareStatement("insert into userinfo(username,password,name,id,phone)"+"value(?,?,?,?,?)");
                        psql.setString(1, usernames);
                        psql.setString(2, passwords);
                        psql.setString(3, names);
                        psql.setString(4,ids);
                        psql.setString(5, phones);
                        psql.executeUpdate();
                        textArea.setText("注册成功!");
                        psql.close();
                    }
                    contosql.con.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });
    }
}
  • 写回答

3条回答

  • COCO_AS 2017-11-18 14:35
    关注

    请把报的错报上来吧, 没有错怎么帮你分析?

    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝