📄 resetpass.java
字号:
//修改密码界面类
package txl.student.reset ;
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
import javax.swing.JOptionPane ;
import java.sql.* ;
import txl.student.user.Users ;
public class ResetPass extends JPanel implements ActionListener
{
private JLabel lab10, lab20, lab30, lab40 ;
private JLabel lab21, lab31, lab41 ;
private JTextField text1 ;
private JPasswordField text2, text3, text4 ;
private JButton ok, reset, reButton ;
private Box baseBox, box1, box2, box3 ;
private JPanel pButton, pCenter;
private Users user = null ;
public void setUsers(Users user)
{
this.user = user ;
}
public Users getUsers()
{
return this.user ;
}
public JTextField getText1()
{
return this.text1 ;
}
public JTextField getText2()
{
return this.text2 ;
}
public JTextField getText3()
{
return this.text3 ;
}
public JTextField getText4()
{
return this.text4 ;
}
public ResetPass()
{
lab10 = new JLabel("用户名:") ;
lab20 = new JLabel("原密码:") ;
lab30 = new JLabel("新密码:") ;
lab40 = new JLabel("确认密码:") ;
lab21 = new JLabel("输入原密码!") ;
lab31 = new JLabel("输入新密码!") ;
lab41 = new JLabel("新密码确认!") ;
text1 = new JTextField(12) ;
text1.setEnabled(false) ;
text2 = new JPasswordField(12) ;
text3 = new JPasswordField(12) ;
text4 = new JPasswordField(12) ;
text2.setEchoChar('*') ;
text3.setEchoChar('*') ;
text4.setEchoChar('*') ;
ok = new JButton("确认") ;
reset = new JButton("取消") ;
reButton = new JButton("返回") ;
ok.addActionListener(this) ;
reset.addActionListener(this) ;
reButton.addActionListener(this) ;
pButton = new JPanel() ;
pCenter = new JPanel() ;
pButton.add(ok) ;
pButton.add(reButton) ;
pButton.add(reset) ;
box1 = Box.createVerticalBox() ;
box1.add(Box.createVerticalStrut(26)) ;
box1.add(lab10) ;
box1.add(Box.createVerticalStrut(8)) ;
box1.add(lab20) ;
box1.add(Box.createVerticalStrut(8)) ;
box1.add(lab30) ;
box1.add(Box.createVerticalStrut(8)) ;
box1.add(lab40) ;
box2 = Box.createVerticalBox() ;
box2.add(Box.createVerticalStrut(26)) ;
box2.add(text1) ;
box2.add(Box.createVerticalStrut(8)) ;
box2.add(text2) ;
box2.add(Box.createVerticalStrut(8)) ;
box2.add(text3) ;
box2.add(Box.createVerticalStrut(8)) ;
box2.add(text4) ;
box3 = Box.createVerticalBox() ;
box3.add(Box.createVerticalStrut(26)) ;
box3.add(new JLabel(" ")) ;
box3.add(Box.createVerticalStrut(8)) ;
box3.add(lab21) ;
box3.add(Box.createVerticalStrut(8)) ;
box3.add(lab31) ;
box3.add(Box.createVerticalStrut(8)) ;
box3.add(lab41) ;
baseBox = Box.createHorizontalBox() ;
baseBox.add(box1) ;
baseBox.add(Box.createHorizontalStrut(10)) ;
baseBox.add(box2) ;
baseBox.add(Box.createHorizontalStrut(10)) ;
baseBox.add(box3) ;
pCenter.add(baseBox) ;
this.setLayout(new BorderLayout()) ;
this.add(pCenter, BorderLayout.CENTER) ;
this.add(pButton, BorderLayout.SOUTH) ;
this.validate() ;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==ok) //确认修改
{
String userName = this.getUsers().getUserName() ;
String userPass = this.getUsers().getUserPass() ;
String uPass2 = text2.getText().trim() ;
String uPass3 = text3.getText().trim() ;
String uPass4 = text4.getText().trim() ;
if(uPass2!=null||uPass2.length()!=0)
{
if(uPass3==null||uPass3.length()==0)
{
lab31.setText("请输入新密码!") ;
}
else if(uPass3.equals(uPass4))
{
if(userPass.equals(uPass2)) //修改密码成功
{ //一确认对话框
int n = JOptionPane.showConfirmDialog(this,"确认要修改密码吗?", "",JOptionPane.YES_NO_OPTION) ;
if(n==JOptionPane.YES_OPTION)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:TXL2008","scott","txl2008");
Statement stmt = conn.createStatement( );
String sql = "update users set user_PassWord='"+uPass3+"' where user_name='"+userName+"'" ;
//ResultSet rset =
stmt.executeUpdate(sql);
//rset.close() ;
stmt.close() ;
conn.close() ;
}
catch(Exception ex)
{ }
// 警告对话框
JOptionPane.showMessageDialog(this,"密码修改成功 !\n下次以新密码登陆","",JOptionPane.WARNING_MESSAGE) ;
this.setVisible(false) ;
}//确认修改密码
else if(n==JOptionPane.NO_OPTION)
{
//不修改密码
this.setVisible(false) ;
}
}
else
{ //两次新密码不同
text2.setText("") ;
text3.setText("") ;
text4.setText("") ;
lab21.setText("原密码错误!") ;
}
}
else
{
text2.setText("") ;
text3.setText("") ;
text4.setText("") ;
lab41.setText("两次的密码不同!") ;
}
}
else
{
lab21.setText("请先输入原密码!!") ;
text3.setText("") ;
text4.setText("") ;
}
}//ok
else if(e.getSource()==reButton) // 返回
{
this.setVisible(false) ;
}
else if(e.getSource()==reset) //取消
{
text2.setText("") ;
text3.setText("") ;
text4.setText("") ;
}
}//actionPerformed(ActionEvent e)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -