JAVA完成簡略體系上岸注冊模塊。本站提示廣大學習愛好者:(JAVA完成簡略體系上岸注冊模塊)文章只能為提供參考,不一定能成為您想要的結果。以下是JAVA完成簡略體系上岸注冊模塊正文
後期預備
起首要先明白有個年夜體的思緒,要完成甚麼樣的功效,懂得完成全部模塊要應用到哪些方面的常識,和從做的進程中去發明本身的缺乏。技巧方面的提高年夜都都須要從理論中出來的。
功效:用戶注冊功效+體系登錄功效+生成驗證碼
常識:窗體設計、數據庫設計、JavaBean封裝屬性、JDBC完成對數據庫的銜接、驗證碼(包含黑色驗證碼)生成技巧,還有就些好比像應用正則表達式校驗用戶注冊信息、隨機取得字符串、對文本可用字符數的掌握等
設計的模塊預覽圖:
黑色驗證碼預覽圖:
所用數據庫:MySQL
數據庫設計
創立一個數據庫db_database01,個中包括一個表格tb_user,用來保留用戶的注冊的數據。
個中包括4個字段
id int(11)
username varchar(15)
password varchar(20)
email varchar(45)
MySQL語句可以如許設計:
create schema db_database01; use db_database01; create table tb_user( id int(11) not null auto_increment primary key, username varchar(15) not null, password varchar(20) not null, email varchar(45) not null ); insert into tb_user values(1,"lixiyu","lixiyu",[email protected]);
如許把lixiyu作為用戶名。
select語句檢討一下所樹立的表格:
編寫JavaBean封裝用戶屬性
package com.lixiyu.model; public class User { private int id;// 編號 private String username;// 用戶名 private String password;// 暗碼 private String email;// 電子郵箱 public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
編寫JDBC對象類
將與數據庫操作相干的代碼放置在DBConfig接口和DBHelper類中
DBConfig接口用於保留數據庫、用戶名和暗碼信息
代碼:
package com.lixiyu.util; public interface DBConfig { String databaseName = "db_database01";// 數據庫稱號 String username = "root";// 數據庫用戶名 String password = "lixiyu";// 數據庫暗碼 }
為簡化JDBC開辟,DBHelper應用了了Commons DbUtil組合。
DBHelper類繼續了DBConfig接口,該類中包括4種辦法:
(1)getConnection()辦法:取得數據庫銜接,應用MySQL數據源來簡化編程,防止因加載數據庫驅動而產生異常。
(2)exists()辦法:斷定輸出的用戶名能否存在。
(3)check()辦法:當用戶輸出用戶名和暗碼,查詢應用check()辦法能否准確。
(4)save()辦法:用戶輸出正當注冊信息後,,將信息停止保留。
具體代碼:
package com.lixiyu.util; import java.sql.Connection; import java.sql.SQLException; import java.util.Arrays; import java.util.List; import org.apache.commons.dbutils.DbUtils; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.ResultSetHandler; import org.apache.commons.dbutils.handlers.ColumnListHandler; import org.apache.commons.dbutils.handlers.ScalarHandler; import org.apache.commons.lang.StringEscapeUtils; import com.lixiyu.model.User; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; public class DBHelper implements DBConfig { /* * 應用MySQL數據源取得數據庫銜接對象 * * @return:MySQL銜接對象,假如取得掉敗前往null */ public static Connection getConnection() { MysqlDataSource mds = new MysqlDataSource();// 創立MySQL數據源 mds.setDatabaseName(databaseName);// 設置數據庫稱號 mds.setUser(username);// 設置數據庫用戶名 mds.setPassword(password);// 設置數據庫暗碼 try { return mds.getConnection();// 取得銜接 } catch (SQLException e) { e.printStackTrace(); } return null;// 假如獲得掉敗就前往null } /* * 斷定指定用戶名的用戶能否存在 * * @return:假如存在前往true,不存在或許查詢掉敗前往false */ public static boolean exists(String username) { QueryRunner runner = new QueryRunner();// 創立QueryRunner對象 String sql = "select id from tb_user where username = '" + username + "';";// 界說查詢語句 Connection conn = getConnection();// 取得銜接 ResultSetHandler<List<Object>> rsh = new ColumnListHandler();// 創立成果集處置類 try { List<Object> result = runner.query(conn, sql, rsh);// 取得查詢成果 if (result.size() > 0) {// 假如列表中存在數據 return true;// 前往true } else {// 假如列表中沒稀有據 return false;// 前往false } } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn);// 封閉銜接 } return false;// 假如產生異常前往false } /* * 驗證用戶名和暗碼能否准確 應用Commons Lang組件本義字符串防止SQL注入 * * @return:假如准確前往true,毛病前往false */ public static boolean check(String username, char[] password) { username = StringEscapeUtils.escapeSql(username);// 將用戶輸出的用戶名本義 QueryRunner runner = new QueryRunner();// 創立QueryRunner對象 String sql = "select password from tb_user where username = '" + username + "';";// 界說查詢語句 Connection conn = getConnection();// 取得銜接 ResultSetHandler<Object> rsh = new ScalarHandler();// 創立成果集處置類 try { String result = (String) runner.query(conn, sql, rsh);// 取得查詢成果 char[] queryPassword = result.toCharArray();// 將查詢到得暗碼轉換成字符數組 if (Arrays.equals(password, queryPassword)) {// 假如暗碼雷同則前往true Arrays.fill(password, '0');// 清空傳入的暗碼 Arrays.fill(queryPassword, '0');// 清空查詢的暗碼 return true; } else {// 假如暗碼分歧則前往false Arrays.fill(password, '0');// 清空傳入的暗碼 Arrays.fill(queryPassword, '0');// 清空查詢的暗碼 return false; } } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn);// 封閉銜接 } return false;// 假如產生異常前往false } /* * 保留用戶輸出的注冊信息 * * @return:假如保留勝利前往true,保留掉敗前往false */ public static boolean save(User user) { QueryRunner runner = new QueryRunner();// 創立QueryRunner對象 String sql = "insert into tb_user (username, password, email) values (?, ?, ?);";// 界說查詢語句 Connection conn = getConnection();// 取得銜接 Object[] params = { user.getUsername(), user.getPassword(), user.getEmail() };// 取得傳遞的參數 try { int result = runner.update(conn, sql, params);// 保留用戶 if (result > 0) {// 假如保留勝利前往true return true; } else {// 假如保留掉敗前往false return false; } } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn);// 封閉銜接 } return false;// 假如產生異常前往false } }
體系登錄
1.1窗體設計
應用BoxLayout結構,將控件分列方法設置從上至下:
contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.PAGE_AXIS));
窗體應用了標簽、文本域、暗碼域和按鈕等控件
完成代碼:
public class login extends JFrame{ private static final long serialVersionUID = -4655235896173916415L; private JPanel contentPane; private JTextField usernameTextField; private JPasswordField passwordField; private JTextField validateTextField; private String randomText; public static void main(String args[]){ try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable(){ public void run(){ try{ login frame=new login(); frame.setVisible(true); }catch(Exception e){ e.printStackTrace(); } } }); } public login(){ setTitle("體系登錄"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane=new JPanel(); setContentPane(contentPane); contentPane.setLayout(new BoxLayout(contentPane,BoxLayout.PAGE_AXIS)); JPanel usernamePanel=new JPanel(); contentPane.add(usernamePanel); JLabel usernameLable=new JLabel("\u7528\u6237\u540D\uFF1A"); usernameLable.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); usernamePanel.add(usernameLable); usernameTextField=new JTextField(); usernameTextField.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); usernamePanel.add(usernameTextField); usernameTextField.setColumns(10); JPanel passwordPanel = new JPanel(); contentPane.add(passwordPanel); JLabel passwordLabel = new JLabel("\u5BC6 \u7801\uFF1A"); passwordLabel.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); passwordPanel.add(passwordLabel); passwordField = new JPasswordField(); passwordField.setColumns(10); passwordField.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); passwordPanel.add(passwordField); JPanel validatePanel = new JPanel(); contentPane.add(validatePanel); JLabel validateLabel = new JLabel("\u9A8C\u8BC1\u7801\uFF1A"); validateLabel.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); validatePanel.add(validateLabel); validateTextField = new JTextField(); validateTextField.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); validatePanel.add(validateTextField); validateTextField.setColumns(5); randomText = RandomStringUtils.randomAlphanumeric(4); CAPTCHALabel label = new CAPTCHALabel(randomText);//隨機驗證碼 label.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); validatePanel.add(label); JPanel buttonPanel=new JPanel(); contentPane.add(buttonPanel); JButton submitButton=new JButton("登錄"); submitButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { do_submitButton_actionPerformed(e); } }); submitButton.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); buttonPanel.add(submitButton); JButton cancelButton=new JButton("加入"); cancelButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ do_cancelButton_actionPerformed(e); } }); cancelButton.setFont(new Font("微軟雅黑",Font.PLAIN,15)); buttonPanel.add(cancelButton); pack();// 主動調劑窗體年夜小 setLocation(com.lixiyu.util.SwingUtil.centreContainer(getSize()));// 讓窗體居中顯示 }
窗體居中顯示:
public class SwingUtil { /* * 依據容器的年夜小,盤算居中顯示時左上角坐標 * * @return 容器左上角坐標 */ public static Point centreContainer(Dimension size) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();// 取得屏幕年夜小 int x = (screenSize.width - size.width) / 2;// 盤算左上角的x坐標 int y = (screenSize.height - size.height) / 2;// 盤算左上角的y坐標 return new Point(x, y);// 前往左上角坐標 } }
1.2獲得及繪制驗證碼
public class CAPTCHALabel extends JLabel { private static final long serialVersionUID = -963570191302793615L; private String text;// 用於保留生成驗證圖片的字符串 public CAPTCHALabel(String text) { this.text = text; setPreferredSize(new Dimension(60, 36));// 設置標簽的年夜小 } @Override public void paint(Graphics g) { super.paint(g);// 挪用父類的結構辦法 g.setFont(new Font("微軟雅黑", Font.PLAIN, 16));// 設置字體 g.drawString(text, 5, 25);// 繪制字符串 } }
*黑色驗證碼:
public class ColorfulCAPTCHALabel extends JLabel { private static final long serialVersionUID = -963570191302793615L; private String text;// 用於保留生成驗證圖片的字符串 private Color[] colors = { Color.BLACK, Color.BLUE, Color.CYAN, Color.DARK_GRAY, Color.GRAY, Color.GREEN, Color.LIGHT_GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE, Color.YELLOW };// 界說畫筆色彩數組 public ColorfulCAPTCHALabel(String text) { this.text = text; setPreferredSize(new Dimension(60, 36));// 設置標簽的年夜小 } @Override public void paint(Graphics g) { super.paint(g);// 挪用父類的結構辦法 g.setFont(new Font("微軟雅黑", Font.PLAIN, 16));// 設置字體 for (int i = 0; i < text.length(); i++) { g.setColor(colors[RandomUtils.nextInt(colors.length)]); g.drawString("" + text.charAt(i), 5 + i * 13, 25);// 繪制字符串 } } }
1.3非空校驗
if (username.isEmpty()) {// 斷定用戶名能否為空 JOptionPane.showMessageDialog(this, "用戶名不克不及為空!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } if (new String(password).isEmpty()) {// 斷定暗碼能否為空 JOptionPane.showMessageDialog(this, "暗碼不克不及為空!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } if (validate.isEmpty()) {// 斷定驗證碼能否為空 JOptionPane.showMessageDialog(this, "驗證碼不克不及為空!", "正告信息", JOptionPane.WARNING_MESSAGE); return; }
1.4正當性校驗
if (!DBHelper.exists(username)) {// 假如用戶名不存在則停止提醒 JOptionPane.showMessageDialog(this, "用戶名不存在!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } if (!DBHelper.check(username, password)) {// 假如暗碼毛病則停止提醒 JOptionPane.showMessageDialog(this, "暗碼毛病!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } if (!validate.equals(randomText)) {// 假如校驗碼不婚配則停止提醒 JOptionPane.showMessageDialog(this, "驗證碼毛病!", "正告信息", JOptionPane.WARNING_MESSAGE); return; }
1.5顯示主窗體
EventQueue.invokeLater(new Runnable() { @Override public void run() { try { MainFrame frame = new MainFrame();// 創立主窗體 frame.setVisible(true);// 設置主窗體可見 } catch (Exception e) { e.printStackTrace(); } } }); dispose();// 將登錄窗體燒毀 }
設計主窗體(比擬簡略這個):
public MainFrame() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 設置單擊封閉窗體按鈕時履行的操作 setSize(450, 300);// 設置窗體年夜小 contentPane = new JPanel();// 創立面板 contentPane.setLayout(new BorderLayout(0, 0));// 設置面板結構應用界限結構 setContentPane(contentPane);// 運用面板 JLabel tipLabel = new JLabel("祝賀您勝利登錄體系!");// 創立標簽 tipLabel.setFont(new Font("微軟雅黑", Font.PLAIN, 40));// 設置標簽字體 contentPane.add(tipLabel, BorderLayout.CENTER);// 運用標簽 setLocation(SwingUtil.centreContainer(getSize()));// 讓窗體居中顯示 }
用戶注冊
1.1窗體設計
public class Register extends JFrame { /** * */ private static final long serialVersionUID = 2491294229716316338L; private JPanel contentPane; private JTextField usernameTextField; private JPasswordField passwordField1; private JPasswordField passwordField2; private JTextField emailTextField; private JLabel tipLabel = new JLabel();// 顯示提醒信息 /** * Launch the application. */ public static void main(String[] args) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Throwable e) { e.printStackTrace(); } EventQueue.invokeLater(new Runnable() { @Override public void run() { try { Register frame = new Register(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public Register() { setTitle("\u7528\u6237\u6CE8\u518C"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane = new JPanel(); setContentPane(contentPane); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); JPanel usernamePanel = new JPanel(); contentPane.add(usernamePanel); JLabel usernameLabel = new JLabel("\u7528 \u6237 \u540D\uFF1A"); usernameLabel.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); usernamePanel.add(usernameLabel); usernameTextField = new JTextField(); usernameTextField.setToolTipText("\u8BF7\u8F93\u51655~15\u4E2A\u7531\u5B57\u6BCD\u6570\u5B57\u4E0B\u5212\u7EBF\u7EC4\u6210\u7684\u5B57\u7B26\u4E32"); AbstractDocument doc = (AbstractDocument) usernameTextField.getDocument(); doc.setDocumentFilter(new DocumentSizeFilter(15));// 限制文本域內可以輸出字符長度為15 doc.addDocumentListener(new DocumentSizeListener(tipLabel, 15)); usernameTextField.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); usernamePanel.add(usernameTextField); usernameTextField.setColumns(10); JPanel passwordPanel1 = new JPanel(); contentPane.add(passwordPanel1); JLabel passwordLabel1 = new JLabel("\u8F93\u5165\u5BC6\u7801\uFF1A"); passwordLabel1.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); passwordPanel1.add(passwordLabel1); passwordField1 = new JPasswordField(); doc = (AbstractDocument) passwordField1.getDocument(); doc.setDocumentFilter(new DocumentSizeFilter(20));// 限制暗碼域內可以輸出字符長度為20 doc.addDocumentListener(new DocumentSizeListener(tipLabel, 20)); passwordField1.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); passwordField1.setColumns(10); passwordPanel1.add(passwordField1); JPanel passwordPanel2 = new JPanel(); contentPane.add(passwordPanel2); JLabel passwordLabel2 = new JLabel("\u786E\u8BA4\u5BC6\u7801\uFF1A"); passwordLabel2.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); passwordPanel2.add(passwordLabel2); passwordField2 = new JPasswordField(); doc = (AbstractDocument) passwordField2.getDocument(); doc.setDocumentFilter(new DocumentSizeFilter(20));// 限制暗碼域內可以輸出字符長度為20 doc.addDocumentListener(new DocumentSizeListener(tipLabel, 20)); passwordField2.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); passwordField2.setColumns(10); passwordPanel2.add(passwordField2); JPanel emailPanel = new JPanel(); contentPane.add(emailPanel); JLabel emailLabel = new JLabel("\u7535\u5B50\u90AE\u7BB1\uFF1A"); emailLabel.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); emailPanel.add(emailLabel); emailTextField = new JTextField(); doc = (AbstractDocument) emailTextField.getDocument(); doc.setDocumentFilter(new DocumentSizeFilter(45));// 限制文本域內可以輸出字符長度為45 doc.addDocumentListener(new DocumentSizeListener(tipLabel, 45)); emailTextField.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); emailPanel.add(emailTextField); emailTextField.setColumns(10); JPanel buttonPanel = new JPanel(); contentPane.add(buttonPanel); JButton submitButton = new JButton("\u63D0\u4EA4"); submitButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { do_submitButton_actionPerformed(e); } }); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); tipLabel.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); buttonPanel.add(tipLabel); Component glue = Box.createGlue(); buttonPanel.add(glue); submitButton.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); buttonPanel.add(submitButton); JButton cancelButton = new JButton("\u53D6\u6D88"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { do_cancelButton_actionPerformed(e); } }); cancelButton.setFont(new Font("微軟雅黑", Font.PLAIN, 15)); buttonPanel.add(cancelButton); pack();// 主動調劑窗體年夜小 setLocation(SwingUtil.centreContainer(getSize()));// 讓窗體居中顯示 }
1.2用DocumentFilter限制文本可用字符數
public class DocumentSizeFilter extends DocumentFilter { private int maxSize;// 取得文本的最年夜長度 public DocumentSizeFilter(int maxSize) { this.maxSize = maxSize;// 取得用戶輸出的最年夜長度 } @Override public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { if ((fb.getDocument().getLength() + string.length()) <= maxSize) {// 假如拔出操作完成後小於最年夜長度 super.insertString(fb, offset, string, attr);// 挪用父類中的辦法 } else { Toolkit.getDefaultToolkit().beep();// 收回提醒聲響 } } @Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { if ((fb.getDocument().getLength() + text.length() - length) <= maxSize) {// 假如調換操作完成後小於最年夜長度 super.replace(fb, offset, length, text, attrs);// 挪用父類中的辦法 } else { Toolkit.getDefaultToolkit().beep();// 收回提醒聲響 } } }
1.3用DocumentListener接話柄現顯示文本控件已用字符
public class DocumentSizeListener implements DocumentListener { private JLabel tipLabel; private int maxSize; public DocumentSizeListener(JLabel tipLabel, int maxSize) { this.tipLabel = tipLabel; this.maxSize = maxSize; } @Override public void insertUpdate(DocumentEvent e) { setTipText(e); } @Override public void removeUpdate(DocumentEvent e) { setTipText(e); } @Override public void changedUpdate(DocumentEvent e) { setTipText(e); } private void setTipText(DocumentEvent e) { Document doc = e.getDocument();// 取得文檔對象 tipLabel.setForeground(Color.BLACK);// 設置字體色彩 if (doc.getLength() > (maxSize * 4 / 5)) {// 假如已輸出字符長度年夜於最年夜長度的80% tipLabel.setForeground(Color.RED);// 應用白色顯示提醒信息 } else { tipLabel.setForeground(Color.BLACK);// 應用黑色顯示提醒信息 } tipLabel.setText("提醒信息:" + doc.getLength() + "/" + maxSize); } }
1.4非空校驗
if (username.isEmpty()) {// 斷定用戶名能否為空 JOptionPane.showMessageDialog(this, "用戶名不克不及為空!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } if (new String(password1).isEmpty()) {// 斷定暗碼能否為空 JOptionPane.showMessageDialog(this, "暗碼不克不及為空!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } if (new String(password2).isEmpty()) {// 斷定確認暗碼能否為空 JOptionPane.showMessageDialog(this, "確認暗碼不克不及為空!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } if (email.isEmpty()) {// 斷定電子郵箱能否為空 JOptionPane.showMessageDialog(this, "電子郵箱不克不及為空!", "正告信息", JOptionPane.WARNING_MESSAGE); return; }
1.5應用正則表達式校驗字符串(正當性校驗)
// 校驗用戶名能否正當 if (!Pattern.matches("\\w{5,15}", username)) { JOptionPane.showMessageDialog(this, "請輸出正當的用戶名!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } // 校驗兩次輸出的暗碼能否雷同 if (!Arrays.equals(password1, password2)) { JOptionPane.showMessageDialog(this, "兩次輸出的暗碼分歧!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } // 校驗電子郵箱能否正當 if (!Pattern.matches("\\w+@\\w+\\.\\w+", email)) { JOptionPane.showMessageDialog(this, "請輸出正當的電子郵箱!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } // 校驗用戶名能否存在 if (DBHelper.exists(username)) { JOptionPane.showMessageDialog(this, "用戶名曾經存在", "正告信息", JOptionPane.WARNING_MESSAGE); return; }
1.6保留注冊信息
User user = new User(); user.setUsername(username); user.setPassword(new String(password1)); user.setEmail(email); Arrays.fill(password1, '0');// 清空保留暗碼的字符數組 Arrays.fill(password2, '0');// 清空保留暗碼的字符數組 if (DBHelper.save(user)) { JOptionPane.showMessageDialog(this, "用戶注冊勝利!", "提醒信息", JOptionPane.INFORMATION_MESSAGE); return; } else { JOptionPane.showMessageDialog(this, "用戶注冊掉敗!", "正告信息", JOptionPane.WARNING_MESSAGE); return; } }
至此,一個簡略而有完全的上岸注冊模塊就完成了。
以上就是本文的全體內容,願望年夜家可以愛好。