📄 edit_password.java
字号:
package clinique;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.text.*;
import java.awt.*;
import java.lang.String;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
import java.util.*;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.SQLException;
import java.awt.Font;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class edit_password extends JPanel {
login s=new login();
String u=s.username;
String p=s.userpassword;
String a;
String b;
String x;
public edit_password() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jTname.setText(u);
jjPassword.setEditable(false);
jjPassword.setText(p);
jLabel1.setText("用户名:");
jLabel1.setBounds(new Rectangle(149, 129, 60, 15));
jLabel2.setToolTipText("");
jLabel2.setText("旧密码:");
jLabel2.setBounds(new Rectangle(148, 177, 53, 15));
jLabel3.setText("新密码:");
jLabel3.setBounds(new Rectangle(148, 216, 56, 15));
jLabel4.setText("确认密码:");
jLabel4.setBounds(new Rectangle(137, 257, 73, 15));
jTname.setEditable(false);
jTname.setBounds(new Rectangle(234, 125, 133, 21));
jBorder.setBounds(new Rectangle(148, 346, 94, 25));
jBorder.setText("确认提交");
jBorder.addActionListener(new edit_password_jBorder_actionAdapter(this));
jBexit.setBounds(new Rectangle(286, 347, 87, 25));
jBexit.setText("取消");
jBexit.addActionListener(new edit_password_jBexit_actionAdapter(this));
jrPassword.setBounds(new Rectangle(234, 250, 133, 25));
jjPassword.setBounds(new Rectangle(234, 166, 133, 24));
jxPassword.setBounds(new Rectangle(234, 207, 133, 24));
jLabel5.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
jLabel5.setText("医生密码修改");
jLabel5.setBounds(new Rectangle(57, 42, 136, 42));
this.add(jLabel5);
this.add(jTname);
this.add(jjPassword);
this.add(jLabel1);
this.add(jLabel2);
this.add(jxPassword);
this.add(jrPassword);
this.add(jLabel4);
this.add(jLabel3);
this.add(jBorder);
this.add(jBexit);
}
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTname = new JTextField();
JButton jBorder = new JButton();
JButton jBexit = new JButton();
JPasswordField jrPassword = new JPasswordField();
JPasswordField jjPassword = new JPasswordField();
JPasswordField jxPassword = new JPasswordField();
javax.swing.JLabel jLabel5 = new JLabel();
public void jBorder_actionPerformed(ActionEvent e) {
a=jxPassword.getText();
b=jrPassword.getText();
if(jxPassword.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"请输入你要的新密码!");
jxPassword.requestFocus();
}
else if(jrPassword.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"请再次输入你要的新密码!");
jrPassword.requestFocus();
}
else if(!a.equals(b))
{
JOptionPane.showMessageDialog(null,"两次输入的密码不一致请重新输入!");
jxPassword.setText("");
jrPassword.setText("");
jxPassword.requestFocus();
}
else
{
x=jrPassword.getText();
int result=JOptionPane.showConfirmDialog(null," 用户名:"+u+"\n"+" 你的新密码是:"+x+
"\n\n"+"你确认要提交修改的密码吗?");
if(result==JOptionPane.YES_OPTION)
{
edit_pass();
}
else
{
JOptionPane.showMessageDialog(null,"你的密码尚未修改!");
}
}
}
private void edit_pass()
{
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
try {
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique";
Connection con = DriverManager.getConnection(url,"sa","");
String sqlStr;
sqlStr="update doctor set password=\'"+a+"\' where name=\'"+u+"\'";
Statement s = con.createStatement();
s.executeUpdate(sqlStr);
JOptionPane.showMessageDialog(null,"密码修改成功! 请记住好你的新密码!");
jxPassword.setText("");
jrPassword.setText("");
s.close();
con.close();
} catch (SQLException ce) {
System.out.println(ce);
}
}
public void jBexit_actionPerformed(ActionEvent e) {
jxPassword.setText("");
jrPassword.setText("");
}
}
class edit_password_jBexit_actionAdapter implements ActionListener {
private edit_password adaptee;
edit_password_jBexit_actionAdapter(edit_password adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jBexit_actionPerformed(e);
}
}
class edit_password_jBorder_actionAdapter implements ActionListener {
private edit_password adaptee;
edit_password_jBorder_actionAdapter(edit_password adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jBorder_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -