📄 alter_pwd.java
字号:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
import java.sql.PreparedStatement;
import javax.swing.*;;
public class Alter_pwd extends JFrame implements ActionListener
{
String yonghuming;
String pwd;
String mimaed;
String table;
String jiemima;
String jiename;
private static final int DEFAULT_WIDTH = 400;
private static final int DEFAULT_HEIFHT = 300;
static ResultSet rs;
static Connection con;
static PreparedStatement ps;
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
JLabel xingming;
JLabel mima;
JLabel space1;
JLabel space2;
JTextField tf_name;
JTextField tf_pwd;
JButton xiugai;
JButton exit;
public Alter_pwd()
{
super.setSize(DEFAULT_WIDTH,DEFAULT_HEIFHT);
super.setTitle("欢迎光临学生成绩管理系统!");
xingming=new JLabel("用户名:");
mima=new JLabel("密 码:");
space2=new JLabel(" ");
space1=new JLabel(" ");
tf_name=new JTextField(10);
tf_name.setEditable(false);
tf_pwd=new JTextField(10);
exit=new JButton("退 出");
exit.addActionListener(this);
xiugai=new JButton("修 改");
xiugai.addActionListener(this);
set(0,0,1,1,xingming);
set(1,0,1,1,tf_name);
set(0,1,1,1,mima);
set(1,1,1,1,tf_pwd);
set(0,2,1,1,space1);
set(1,2,1,1,space2);
set(0,3,1,1,xiugai);
set(1,3,1,1,exit);
setLocation(300,80);
setLayout(gbl);
User_login log=new User_login();
yonghuming=log.mingzi;
table=log.table_name;
pwd=log.pass;
jiemima=log.mima_name;
System.out.println(jiemima);
jiename=log.ming_name;
tf_pwd.setText(pwd);
tf_name.setText(yonghuming);
}
public void actionPerformed(ActionEvent e)
{
Object obj=e.getSource();
if(obj==xiugai)
{
mimaed=tf_pwd.getText().trim();
try
{
if(mimaed.length()==0)
{
JOptionPane.showMessageDialog((Component)null,"密码不能为空!请输入!","提示信息",JOptionPane.ERROR_MESSAGE);
tf_pwd.requestFocus();
}
else
{
if(table=="administrator")
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:StudentScore","sa","");
ps=con.prepareStatement("update administrator set admin_password=? where admin_no=?");
ps.setString(1,mimaed);
ps.setString(2,yonghuming);
JOptionPane.showMessageDialog((Component)null,"确定修改吗?","提示信息",JOptionPane.QUESTION_MESSAGE);
rs=ps.executeQuery();
}
if(table=="teacher")
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:StudentScore","sa","");
ps=con.prepareStatement("update teacher set teacher_password=? where teacher_no=?");
ps.setString(1,mimaed);
ps.setString(2,yonghuming);
JOptionPane.showMessageDialog((Component)null,"确定修改吗?","提示信息",JOptionPane.QUESTION_MESSAGE);
rs=ps.executeQuery();
}
if(table=="student")
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:StudentScore","sa","");
ps=con.prepareStatement("update student set student_password=? where student_no=?");
ps.setString(1,mimaed);
ps.setString(2,yonghuming);
JOptionPane.showMessageDialog((Component)null,"确定修改吗?","提示信息",JOptionPane.QUESTION_MESSAGE);
rs=ps.executeQuery();
}
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
if(obj==exit)
{
this.dispose();
Admin_manage ma=new Admin_manage();
ma.setVisible(true);
}
}
public void set(int x,int y,int w,int h,Component com)
{
gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=x;
gbc.gridy=y;
gbc.gridwidth=w;
gbc.gridheight=h;
gbl.setConstraints(com, gbc);
add(com);
}
public static void main(String[] args)
{
Alter_pwd p=new Alter_pwd();
p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -