?? enroll.java
字號:
package scince;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Enroll extends JDialog {
JPanel panel1 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField2 = new JPasswordField();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JButton jButton3 = new JButton();
public Enroll(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public Enroll() {
this(new Frame(), "Enroll", false);
}
private void jbInit() throws Exception {
panel1.setLayout(null);
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(javax.swing.WindowConstants.
DO_NOTHING_ON_CLOSE);
jButton1.setBounds(new Rectangle(56, 232, 90, 35));
jButton1.setText("確定");
jButton1.addActionListener(new Enroll_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(163, 232, 89, 35));
jButton2.setText("重置");
jButton2.addActionListener(new Enroll_jButton2_actionAdapter(this));
jLabel1.setText("新用戶名:");
jLabel1.setBounds(new Rectangle(36, 17, 92, 34));
jTextField1.setBounds(new Rectangle(136, 22, 86, 29));
jLabel2.setText("密碼");
jLabel2.setBounds(new Rectangle(46, 80, 52, 24));
jPasswordField1.setBounds(new Rectangle(138, 77, 82, 30));
jLabel3.setText("重復確認密碼");
jLabel3.setBounds(new Rectangle(22, 154, 73, 26));
jPasswordField2.setBounds(new Rectangle(141, 147, 82, 33));
jLabel4.setText("字母或數字20位以內");
jLabel4.setBounds(new Rectangle(245, 25, 128, 24));
jLabel5.setText("字母或數字20位以內");
jLabel5.setBounds(new Rectangle(247, 78, 113, 31));
jButton3.setBounds(new Rectangle(266, 230, 88, 37));
jButton3.setText("取消退出");
jButton3.addActionListener(new Enroll_jButton3_actionAdapter(this));
panel1.setBackground(Color.magenta);
panel1.add(jButton1);
panel1.add(jTextField1);
panel1.add(jPasswordField1);
panel1.add(jLabel3);
panel1.add(jLabel4);
panel1.add(jLabel5);
panel1.add(jButton2);
panel1.add(jPasswordField2);
panel1.add(jLabel2);
panel1.add(jLabel1);
panel1.add(jButton3);
this.getContentPane().add(panel1, null);
panel1.setBounds(new Rectangle( -2, 0, 409, 336));
}
public void jButton1_actionPerformed(ActionEvent e) {
Connection con;
Statement sql;
ResultSet rs;
String queryString;
String user;
String password;
String password1;
user = jTextField1.getText().trim();
password = jPasswordField1.getText();
password1 = jPasswordField2.getText();
queryString = "select * from 用戶 where 用戶名='" + user + "'";
//判斷用戶名及密碼是否為空
if(user.equals("")||password.equals("")||password1.equals(""))
JOptionPane.showMessageDialog(null, "請輸入用戶名和密碼!", "用戶注冊對話框",
JOptionPane.WARNING_MESSAGE);
if(!user.equals("")&& !password.equals("")&& !password1.equals(""))
{
//檢查兩個密碼是否一致
if(!password.endsWith(password1))
{ JOptionPane.showMessageDialog(null, "密碼不一致!", "用戶注冊對話框",
JOptionPane.WARNING_MESSAGE);
jPasswordField1.setText("");
jPasswordField2.setText("");
}
//檢查用戶名是否已經存在
else
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (java.lang.ClassNotFoundException ee) {
System.err.print("class not find!");
System.err.println(ee.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
sql = con.createStatement();
rs = sql.executeQuery(queryString);
if(rs.next())
{
JOptionPane.showMessageDialog(null, "用戶名已經存在!", "用戶注冊對話框",
JOptionPane.WARNING_MESSAGE);
jTextField1.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
}
else {
queryString="Insert into 用戶 values('"+user+"',"+"'"+password+"')";
sql.executeUpdate(queryString);
JOptionPane.showMessageDialog(null, "用戶申請成功!", "用戶注冊對話框",
JOptionPane.INFORMATION_MESSAGE);
}
}catch(SQLException ex){};
}
}
//this.dispose();
}
public void jButton2_actionPerformed(ActionEvent e) {
jTextField1.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
}
public void jButton3_actionPerformed(ActionEvent e) {
this.dispose();
}
}
class Enroll_jButton3_actionAdapter implements ActionListener {
private Enroll adaptee;
Enroll_jButton3_actionAdapter(Enroll adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class Enroll_jButton2_actionAdapter implements ActionListener {
private Enroll adaptee;
Enroll_jButton2_actionAdapter(Enroll adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Enroll_jButton1_actionAdapter implements ActionListener {
private Enroll adaptee;
Enroll_jButton1_actionAdapter(Enroll adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -