⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addusers.java

📁 基于UML的小区物业管理系统设计:1.对小区所有房屋资料的录入和增
💻 JAVA
字号:
package 小区物业管理系统;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.sql.*;
import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JButton;
import javax.swing.JToggleButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class addusers extends JFrame {
    DBConnection LJ=null;
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JTextField name = new JTextField();
    JPasswordField password = new JPasswordField();
    JPasswordField repassword = new JPasswordField();
    public addusers() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        LJ=new DBConnection();
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(borderLayout1);
        setSize(new Dimension(400, 300));
        setTitle("添加用户");
        jPanel1.setLayout(null);
        jLabel1.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
        jLabel1.setText("新用户名");
        jLabel1.setBounds(new Rectangle(62, 47, 95, 33));
        jLabel2.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
        jLabel2.setText("密  码");
        jLabel2.setBounds(new Rectangle(62, 96, 105, 41));
        jLabel3.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
        jLabel3.setText("确认密码");
        jLabel3.setBounds(new Rectangle(62, 145, 113, 37));
        jButton1.setBounds(new Rectangle(81, 225, 96, 31));
        jButton1.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
        jButton1.setText("确定");
        jButton1.addActionListener(new addusers_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(217, 225, 89, 31));
        jButton2.setFont(new java.awt.Font("宋体", Font.PLAIN, 15));
        jButton2.setText("取消");
        jButton2.addActionListener(new addusers_jButton2_actionAdapter(this));
        name.setBounds(new Rectangle(179, 47, 127, 32));
        password.setBounds(new Rectangle(179, 96, 127, 32));
        repassword.setBounds(new Rectangle(179, 145, 127, 33));
        contentPane.add(jPanel1, java.awt.BorderLayout.CENTER);
        jPanel1.add(jLabel1);
        jPanel1.add(jLabel3);
        jPanel1.add(jButton1);
        jPanel1.add(jButton2);
        jPanel1.add(name);
        jPanel1.add(repassword);
        jPanel1.add(jLabel2);
        jPanel1.add(password);
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        this.dispose();

    }

    public void jButton1_actionPerformed(ActionEvent e) {
        boolean find = false;
        Statement stat = LJ.stat;
        if (!name.getText().equals("")) {
            if (new String(password.getPassword()).equals(new String(repassword.
                    getPassword()))) {
                try {
                    //System.out.println(0);
                    ResultSet rst = stat.executeQuery("select * from USERINFO ");
                    //System.out.println(1);
                    while (rst.next()) {
                        if (rst.getString("ID").equals(name.getText())) {
                            JOptionPane.showMessageDialog(this, "此用户已经存在");
                            password.setText("");
                            repassword.setText("");
                            name.setText("");
                            find = true;
                            break;
                        }
                    }
                    if (!find) {
                        try {
                            //System.out.println(3);
                            stat.executeUpdate("insert into USERINFO values ('" +
                                               name.getText() + "','" +
                                               (new String(password.getPassword())) +
                                               "')");
                            //stat.executeUpdate("delete from USER_INFO WHERE NAME='haha'");
                            System.out.println(4);
                            JOptionPane.showMessageDialog(this, "录入成功");
                            password.setText("");
                            repassword.setText("");
                            name.setText("");

                            LJ.close();
                        } catch (Exception ee) {
                            System.out.print(ee.getStackTrace());
                        }
                    }
                } catch (Exception eee) {
                    System.out.print(eee.getStackTrace());
                }
            } else {
                JOptionPane.showMessageDialog(this, "两次输入密码不一致");
                password.setText("");
                repassword.setText("");
            }

        }
        else
        {
            JOptionPane.showMessageDialog(this, "用户名不能为空!");
        }
    }
}


class addusers_jButton1_actionAdapter implements ActionListener {
    private addusers adaptee;
    addusers_jButton1_actionAdapter(addusers adaptee) {
        this.adaptee = adaptee;
    }

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


class addusers_jButton2_actionAdapter implements ActionListener {
    private addusers adaptee;
    addusers_jButton2_actionAdapter(addusers adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -