?? 6.修改密碼界面.txt
字號:
package library;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
public class Frame6 extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JLabel jLabel2 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JPasswordField jPasswordField2 = new JPasswordField();
JPasswordField jPasswordField3 = new JPasswordField();
Connection conn;
public Frame6() {
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connURL ="jdbc:odbc:library";
String user = "sa";
String pw = "123";
conn=DriverManager.getConnection(connURL,user,pw);
}
catch(Exception e)
{
System.out.println("class no found can not connect to sql server"+e);
}
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(200, 260));
setTitle("修改密碼");
jLabel1.setText("ID");
jButton1.setText("確定");
jButton1.addActionListener(new Frame6_jButton1_actionAdapter(this));
jLabel2.setText("舊密碼");
jTextField1.setToolTipText("");
jLabel3.setText("新密碼");
jLabel4.setText("新密碼");
contentPane.add(jLabel1, new XYConstraints(22, 10, 55, 27));
contentPane.add(jLabel3, new XYConstraints(8, 99, -1, -1));
contentPane.add(jLabel4, new XYConstraints(9, 150, -1, -1));
contentPane.add(jPasswordField1, new XYConstraints(55, 53, 130, 27));
contentPane.add(jLabel2, new XYConstraints(10, 58, -1, -1));
contentPane.add(jPasswordField3, new XYConstraints(55, 145, 130, 27));
contentPane.add(jTextField1, new XYConstraints(56, 9, 130, 27));
contentPane.add(jPasswordField2, new XYConstraints(55, 93, 130, 27));
contentPane.add(jButton1, new XYConstraints(90, 183, 62, 24));
}
public void jButton1_actionPerformed(ActionEvent e) {
F6();
}
void F6(){
try
{
String str6_1,str6_2;
str6_1=jTextField1.getText();
str6_2=new String(jPasswordField1.getPassword());
Statement stmt6_1 = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq6_l= "select * from reader where ID='"+str6_1+"' AND 密碼 = '"+str6_2+"' ";
ResultSet rs6_1 = stmt6_1.executeQuery(sq6_l);
if (!rs6_1.next())
{
JOptionPane.showMessageDialog(this,"帳戶或者密碼錯誤","錯誤",JOptionPane.ERROR_MESSAGE);
}
else{
try{
String str6_3,str6_4;
str6_3=new String(jPasswordField2.getPassword());
str6_4=new String(jPasswordField3.getPassword());
if(str6_3.equals("")||str6_4.equals(""))
{
JOptionPane.showMessageDialog(this,"新密碼不能為空","失敗",JOptionPane.ERROR_MESSAGE);
}
else
{
if(str6_3.equals(str6_4))
{
Statement stmt6_2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sq6_2 = "update reader set 密碼 = '"+str6_3+"' where ID = '"+str6_1+"'";
stmt6_2.executeUpdate(sq6_2);
JOptionPane.showMessageDialog(this,"修改成功","成功",JOptionPane.OK_CANCEL_OPTION);
}
else
{
JOptionPane.showMessageDialog(this, "兩次輸入的新密碼不一致", "失敗",JOptionPane.ERROR_MESSAGE);
}
}
}
catch(Exception e)
{
System.err.println(e);
}
}
}
catch(Exception e)
{
System.err.println(e);
}
} //F6()
}
class Frame6_jButton1_actionAdapter implements ActionListener {
private Frame6 adaptee;
Frame6_jButton1_actionAdapter(Frame6 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -