📄 passwordframe.java
字号:
//密码修改窗口
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.sql.*;
public class PasswordFrame extends JFrame implements ActionListener{
static final long serialVersionUID=80;
JPasswordField newtext,confirmtext;
JButton confirmbutton,cancelbutton;
JLabel newlabel,confirmlabel;
Container container;
Connection con;
Statement sql;
String user;
Toolkit tool;
Image myimage;
Dimension screenSize;
PasswordFrame(String title,String user,Connection con){
super(title);
setSize(216,127);
this.con=con;
try{
sql=con.createStatement();
}
catch(SQLException e){
JOptionPane.showMessageDialog(this,"计算机已与服务器断开连接");
}
this.user=user;
tool=getToolkit();
URL url = getClass().getResource("/images/keys.gif");
if(url!=null){
myimage=tool.getImage(url);
setIconImage(myimage);
}
screenSize=tool.getScreenSize();
container=getContentPane();
container.setBackground(Color.ORANGE);
setResizable(false);
newtext=new JPasswordField(20);
confirmtext=new JPasswordField(20);
confirmbutton=new JButton("确定");
cancelbutton=new JButton("取消");
confirmbutton.addActionListener(this);
cancelbutton.addActionListener(this);
newlabel=new JLabel("新密码");
confirmlabel=new JLabel("确认密码");
container.setLayout(null);
container.add(newlabel);
newlabel.setBounds(10,5,40,30);
container.add(newtext);
newtext.setBounds(50,7,160,26);
container.add(confirmlabel);
confirmlabel.setBounds(0,35,50,30);
container.add(confirmtext);
confirmtext.setBounds(50,37,160,26);
container.add(confirmbutton);
confirmbutton.setBounds(0,65,105,30);
container.add(cancelbutton);
cancelbutton.setBounds(105,65,105,30);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
if(sql!=null){
try{
sql.close();
}
catch(SQLException e1){
JOptionPane.showMessageDialog(null,"计算机已与服务器断开");
}
}
}
});
setLocation((screenSize.width - this.getSize().width) / 2,(screenSize.height - this.getSize().height) / 2);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e){
String s=new String(newtext.getPassword());
String t=new String(confirmtext.getPassword());
String temp="'"+s+"'";
String usertemp="'"+user+"'";
String sqltemp="UPDATE User_Info SET UserPassword = "+temp+" WHERE UserName ="+usertemp;
if(e.getSource()==confirmbutton){
if(s.equals(t)&s.length()<=20&s.length()>=8&t.length()<=20&t.length()>=8){
try{
int n=sql.executeUpdate(sqltemp);
if(n==1){
JOptionPane.showMessageDialog(this,"密码修改成功");
}
else{
JOptionPane.showMessageDialog(this,"密码修改失败");
}
}
catch(SQLException e1){
JOptionPane.showMessageDialog(this,"计算机已与服务器断开");
}
}
if(!s.equals(t)){
JOptionPane.showMessageDialog(this,"两次输入的密码要一致","警告对话框",JOptionPane.WARNING_MESSAGE);
}
if(s.length()>20||s.length()<8||t.length()>20||t.length()<8){
JOptionPane.showMessageDialog(this,"密码的长度要在8到20之间","警告对话框",JOptionPane.WARNING_MESSAGE);
}
}
else{
try{
sql.close();
}
catch(SQLException e2){
JOptionPane.showMessageDialog(this,"计算机已与服务器断开");
}
dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -