📄 studentpsd.java
字号:
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
class studentPassword extends JFrame implements ActionListener
{ Box baseBox,boxV1,boxV2;
TextField psdText, newpText,passwordText;
Label psdLabel,newpLabel,passwordLabel;
Button sureButton;
studentPassword(String s)
{ super(s);
psdLabel=new Label("旧密码",Label.LEFT);
psdText=new TextField(10);
newpLabel=new Label("新密码",Label.LEFT);
newpText=new TextField(10);
passwordText=new TextField(10);
passwordLabel=new Label("确认新密码",Label.LEFT);
sureButton=new Button("确定");
boxV1=Box.createVerticalBox();
boxV1.add(psdLabel);
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(newpLabel);
boxV1.add(Box.createVerticalStrut(8));
boxV1.add(passwordLabel);
boxV2=Box.createVerticalBox();
boxV2.add(psdText);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(newpText);
boxV2.add(Box.createVerticalStrut(8));
boxV2.add(passwordText);
boxV2.add(Box.createVerticalStrut(12));
boxV2.add(sureButton);
baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(1));
baseBox.add(boxV2);
setLayout(new FlowLayout());
add(baseBox);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
newpText.addActionListener(this);
passwordText.addActionListener(this);
sureButton.addActionListener(this);
setBounds(100,100,300,300);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException k){
System.out.println(""+k);
}
try{
con=DriverManager.getConnection("jdbc:odbc:sun","","");
sql=con.createStatement();
String name,key,newkey,updatestr=null,recode;
name=psdText.getText();
key=newpText.getText();
newkey=passwordText.getText();
if(key.equals(newkey)){
String no=LoginWindow.fatherName;
System.out.println("sdfsdf"+LoginWindow.fatherName);
updatestr="UPDATE 学生密码表 SET psd = '" + newpText.getText()+ "' WHERE no='" + 3+ "'";
System.out.println(updatestr);
sql.executeUpdate(updatestr);
con.close();
}
else {
JOptionPane.showMessageDialog(this, "两次密码不相同","错误提示",JOptionPane.ERROR_MESSAGE);
}
}catch(SQLException ee){
System.out.print(ee);
}
}
}
public class studentPsd
{ public static void main(String args[])
{ studentPassword Win=new studentPassword("密码修改") ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -