?? passwordedit_frame.java~16~
字號:
package xscjgl;
import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.sql.ResultSet;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import xscjgl.Jdbcconn;
import java.awt.Font;
import java.awt.Rectangle;
/**
* <p>Title: java xscjgl</p>
*
* <p>Description:學生查成績,管理員輸成績、管理。二種權限的學生成績管理系統 </p>
*
* <p>Copyright: lixing (c) 2006</p>
*
*
* @author 04級計算機教育班 黎興
* @version 1.0
*/
public class PasswordEdit_Frame extends JFrame {
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel1 = new JLabel();
XYLayout xYLayout2 = new XYLayout();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JPasswordField jPasswordField2 = new JPasswordField();
JPasswordField jPasswordField3 = new JPasswordField();
String BeforeUno;
TitledBorder titledBorder1 = new TitledBorder("");
JLabel jLabel4 = new JLabel();
public PasswordEdit_Frame() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
this.setTitle("修改密碼窗體");
this.getContentPane().setBackground(new Color(66, 168, 227));
this.setForeground(Color.lightGray);
jPanel1.setBackground(new Color(241, 249, 249));
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(39, 47, 329, 140));
jPanel1.setLayout(xYLayout2);
jButton1.setBounds(new Rectangle(91, 219, 76, 26));
jButton1.setText("提交");
jButton1.addActionListener(new
PasswordEdit_Frame_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(219, 219, 74, 26));
jButton2.setText("退出");
jButton2.addActionListener(new
PasswordEdit_Frame_jButton2_actionAdapter(this));
jLabel1.setText("請輸入原密碼:");
jLabel2.setText("請輸入新密碼:");
jLabel3.setText("再次輸入新密碼:");
jLabel4.setFont(new java.awt.Font("宋體", Font.BOLD, 16));
jLabel4.setText("修改密碼");
jLabel4.setBounds(new Rectangle(143, 5, 85, 24));
jPanel1.add(jLabel1, new XYConstraints(44, 14, 97, 24));
jPanel1.add(jPasswordField1, new XYConstraints(167, 14, 114, -1));
jPanel1.add(jLabel2, new XYConstraints(44, 53, 96, -1));
jPanel1.add(jLabel3, new XYConstraints(43, 86, 111, -1));
jPanel1.add(jPasswordField2, new XYConstraints(167, 46, 112, -1));
jPanel1.add(jPasswordField3, new XYConstraints(167, 81, 110, -1));
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jButton2, null);
this.getContentPane().add(jLabel4, null);
this.getContentPane().add(jPanel1, null);
}
public void jButton2_actionPerformed(ActionEvent e) {
dispose();
}
public void jButton1_actionPerformed(ActionEvent e) {
String BeforePassword = jPasswordField1.getText().trim().toString();
String NewPassword = jPasswordField2.getText().trim().toString();
String AgainPassword = jPasswordField3.getText().trim().toString();
if (BeforePassword.equals("") || NewPassword.equals("") ||
AgainPassword.equals(""))
{
JOptionPane.showMessageDialog(null, "密碼不能為空,請按要求輸入!");
} else {
//******************************************************************************
//判斷原密碼是否正確
try{
Jdbcconn conn = new Jdbcconn();
conn.OpenConn("tqti","tqti","111111");
String strSQL = "select * from UserTable where Uno='" +
BeforeUno + "'";
ResultSet rs = conn.getResults(strSQL);
rs.first();
String Upassword=rs.getString("Upwd");
if(Upassword.equals(BeforePassword))
{
//驗證新密碼。
if(NewPassword.equals(AgainPassword))
{
//密碼驗證成功。更新密碼。
try{
conn.executeUpdate("update UserTable set Upwd='"+NewPassword+"' where Uno='"+BeforeUno+"'");
System.out.println("update SQL is : update UserTable set Upwd='"+NewPassword+"' where Uno='"+BeforeUno+"'");
JOptionPane.showMessageDialog(null, "密碼修改成功,請牢記您的新密碼");
dispose();
conn.closeStmt();
conn.closeConn();
}catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "密碼修改失敗,請重試!");
System.out.println(ex.getMessage());
}
}else{
JOptionPane.showMessageDialog(null, "兩次新密碼不一致,請重新輸入!");
jPasswordField2.setText("");
jPasswordField3.setText("");
}
}else{
JOptionPane.showMessageDialog(null, "原密碼錯誤,請輸入正確的原始密碼!");
jPasswordField1.setText("");
}
}catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "first exception has catched!");
System.out.println(ex.getMessage());
}
}
}
public static void main(String args[]){
PasswordEdit_Frame passwordFrame = new PasswordEdit_Frame();
passwordFrame.setVisible(true);
passwordFrame.setLocationRelativeTo(null);
passwordFrame.setSize(new Dimension(400,400));
}
}
class PasswordEdit_Frame_jButton1_actionAdapter implements ActionListener {
private PasswordEdit_Frame adaptee;
PasswordEdit_Frame_jButton1_actionAdapter(PasswordEdit_Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class PasswordEdit_Frame_jButton2_actionAdapter implements ActionListener {
private PasswordEdit_Frame adaptee;
PasswordEdit_Frame_jButton2_actionAdapter(PasswordEdit_Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -