📄 studentmanage.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
public class StudentManage {
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
SystemFrame sf=new SystemFrame();
sf.setVisible(true);
}
}
class SystemFrame extends JFrame{
public SystemFrame(){
setTitle("StudentScoresManageSystem");
setSize(400,500);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//添加菜单
jmenu=new JMenuBar();
jmu_stuinfo=new JMenu("学生信息查询");
jmi_info=new JMenuItem("个人信息查询");
jmi_score=new JMenuItem("成绩查询");
jmi_pass=new JMenuItem("修改密码");
jmu_stuinfo.add(jmi_pass);
jmu_stuinfo.add(jmi_info);
jmu_stuinfo.add(jmi_score);
jmenu.add(jmu_stuinfo);
jmu_manage=new JMenu("管理");
jmi_dept=new JMenuItem("系院管理");
jmi_class =new JMenuItem("班级管理");
jmi_student=new JMenuItem("学生管理");
jmi_user=new JMenuItem("用户管理");
jmi_addscore=new JMenuItem("录入成绩");
jmu_manage.add(jmi_dept);
jmu_manage.add(jmi_class);
jmu_manage.add(jmi_student);
jmu_manage.add(jmi_user);
jmu_manage.add(jmi_addscore);
jmenu.add(jmu_manage);
jmu_service=new JMenu("服务");
jmi_allstudent=new JMenuItem("全校学生名单");
jmi_classscore=new JMenuItem("全班成绩");
//jmu_tongji=new JMenu("统计信息");
//jmi_aclass=new JMenuItem("全班统计");
//jmi_acourse=new JMenuItem("一个科目统计");
//jmu_tongji.add(jmi_aclass);
//jmu_tongji.add(jmi_acourse);
jmu_service.add(jmi_allstudent);
jmu_service.add(jmi_classscore);
//jmu_service.add(jmu_tongji);
jmenu.add(jmu_service);
setJMenuBar(jmenu);
/////////设置菜单无效
jmu_stuinfo.setEnabled(false);
jmu_manage.setEnabled(false);
jmu_service.setEnabled(false);
/////添加其他界面
JPanel jp1=new JPanel(new BorderLayout());
JLabel jl=new JLabel(" 学生成绩管理系统欢迎你!");
jl.setSize(300,200);
jl.setLocation(100,0);
jp1.add(jl,BorderLayout.CENTER);
ButtonGroup group=new ButtonGroup();
jrb_stu=new JRadioButton("学生");
jrb_tea=new JRadioButton("管理员");
group.add(jrb_stu);
group.add(jrb_tea);
JPanel jp2=new JPanel();
jp2.add(jrb_stu);
jp2.add(jrb_tea);
jp1.add(jp2,BorderLayout.BEFORE_FIRST_LINE);
JPanel jp3=new JPanel();
jtf_user=new JTextField("",10);
jtf_password=new JTextField("",10);
jp3.add(new JLabel("用户名"));
jp3.add(jtf_user);
jp3.add(new JLabel("口令"));
jp3.add(jtf_password);
jb_ok=new JButton("OK");
jp3.add(jb_ok);
jb_ok.addActionListener(new OKListener());
jp1.add(jp3,BorderLayout.SOUTH);
getContentPane().add(jp1);
this.setForeground(new Color(255,40,50));
///////////添加响应事件
jmi_info.addActionListener(new QueryStudentListener());
jmi_student.addActionListener(new StudentFrameListener());
jmi_score.addActionListener(new ScoreInfoListener());
jmi_pass.addActionListener(new PasswordListener());
jb_ok.addActionListener(new OKListener());
jmi_dept.addActionListener(new DeptFrameListener());
jmi_addscore.addActionListener(new ScoreFrameListener());
jmi_class.addActionListener(new ClassFrameListener());
jmi_user.addActionListener(new UserFrameListener());
jmi_allstudent.addActionListener(new AllStudentNameFrameListener());
jmi_classscore.addActionListener(new CertainClassFrameListener());
/////test
jtf_user.setText("admini");
jtf_password.setText("000");
this.validate();
}
//////查询学生信息的事件响应
class QueryStudentListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
querystudent=new QueryStudentFrame(con,jtf_user.getText());
querystudent.setSize(300,400);
querystudent.pack();
querystudent.setVisible(true);
}
}
///////修改学生信息的事件响应
class StudentFrameListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
studentframe=new StudentFrame(con);
//studentframe.setSize(300,400);
studentframe.pack();
studentframe.setVisible(true);
}
}
///////添加学生成绩信息响应
class ScoreInfoListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
scoreinfo=new ScoreInfoFrame(con,jtf_user.getText());
scoreinfo.pack();
scoreinfo.setVisible(true);
}
}
/////////密码修改
class PasswordListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
passframe=new PasswordFrame(con,jtf_user.getText(),jtf_password.getText());
passframe.pack();
passframe.setVisible(true);
}
}
//////////身份验证
class OKListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(jtf_user.getText().equals("")|| jtf_password.getText().equals("")){
JOptionPane.showMessageDialog(null,"Can not be empty!");
return;
}
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Student");
}catch(ClassNotFoundException e1){
JOptionPane.showMessageDialog(null, e1.getMessage());
System.exit(1);
}
catch(SQLException e2){
JOptionPane.showMessageDialog(null, e2.getMessage());
System.exit(1);
}
finally{
}
if(jrb_stu.isSelected()){
try{
Statement st=con.createStatement();
String sql="select * from users where sf=1";
ResultSet rs=st.executeQuery(sql);
boolean exist=false;
while(rs.next()){
String s1,s2;
s1=rs.getString(1);
s2=rs.getString(2);
if(jtf_user.getText().equals(s1) && jtf_password.getText().equals(s2)){
exist=true;
break;
}
}
if(exist!=true) {
JOptionPane.showMessageDialog(null,"guest wrong!");
return;
}
if(rs.getInt(3)==1){
jmu_stuinfo.setEnabled(true);
}
rs.close();
st.close();
}catch(Exception e1){
JOptionPane.showMessageDialog(null, e1.getMessage());
};
}
else if(jrb_tea.isSelected()){
try{
Statement st=con.createStatement();
String sql="select * from users where sf=0";
ResultSet rs=st.executeQuery(sql);
boolean exist=false;
while(rs.next()){
String s1,s2;
s1=rs.getString(1);
s2=rs.getString(2);
if(jtf_user.getText().equals(s1) && jtf_password.getText().equals(s2)){
exist=true;
break;
}
}
if(exist!=true) {
JOptionPane.showMessageDialog(null,"admini wrong!");
return;
};
/////判别身份
if(rs.getInt(3)==0){
jmu_manage.setEnabled(true);
jmu_service.setEnabled(true);
}
rs.close();
st.close();
}catch(Exception e1){
JOptionPane.showMessageDialog(null, e1.getMessage());
};
}
else{
JOptionPane.showMessageDialog(null, "You do not choose student or a teacher!");
return;
}
getContentPane().removeAll();
getContentPane().setBackground(new Color(0,0,255));
getContentPane().add(new JLabel(" WELCOME TO THIS MANAGESYSTEM!"));
getContentPane().validate();
}
}
/////////////////////////部门响应
class DeptFrameListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
DeptFrame df=new DeptFrame(con);
df.pack();
df.setVisible(true);
}
}
/////////////////////////学生成绩修改响应
class ScoreFrameListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
ScoreFrame sf=new ScoreFrame(con);
sf.pack();
sf.setVisible(true);
}
}
/////////////////////////学生成绩修改响应
class ClassFrameListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
ClassFrame cf=new ClassFrame(con);
cf.pack();
cf.setVisible(true);
}
}
/////////////////////////学生成绩修改响应
class UserFrameListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
UserFrame uf=new UserFrame(con);
uf.pack();
uf.setVisible(true);
}
}
////////////////////////所有学生名单响应
class AllStudentNameFrameListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
AllStudentNameFrame af=new AllStudentNameFrame(con);
af.setSize(400,300);
af.setVisible(true);
}
}
////////////////////////班级成绩信息统计工作
class CertainClassFrameListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
CertainClassFrame af=new CertainClassFrame(con);
af.setSize(400,300);
af.setVisible(true);
}
}
JMenuBar jmenu;
JMenu jmu_stuinfo,jmu_manage,jmu_service;
JMenuItem jmi_info,jmi_score;
JMenuItem jmi_dept,jmi_class,jmi_student,jmi_user,jmi_addscore;
JMenu jmu_tongji;
JMenuItem jmi_pass;
JMenuItem jmi_allstudent,jmi_classscore,jmi_aclass,jmi_acourse;
JTextField jtf_user,jtf_password;
JRadioButton jrb_stu,jrb_tea;
JButton jb_ok;
QueryStudentFrame querystudent;
StudentFrame studentframe;
ScoreInfoFrame scoreinfo;
PasswordFrame passframe;
Connection con;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -