您的当前位置:首页正文

[工学]学生信息管理系统完整源码

2022-03-15 来源:星星旅游
学生信息管理系统完整源代码

注:本系统采用C/S结构,运用Java GUI知识编写,数据库为SQL SERVER 2005,没有采用典型的三级框架结构,所以代码有冗余,仅供参考。

一、

首先创建数据库,包含数据表如下: Admin 管理员表 Admin_ID Admin_Name Admin_Pwd

Student_Info 学生信息表 Stu_ID Stu_Pwd Stu_Name Stu_Sex Stu_Age Class_ID Depart

Teacher_Info 教师信息表 Tea_ID Tea_Pwd Tea_Names Tea_Sex Tea_Age Class_ID Depart

Course 课程表 Course_ID Course_Name Course_Count

SC 选修表 Stu_ID Course_ID Score Tea_ID Varchar(20) Varchar(20) Varchar(10) Varchar(20) Varchar(20) Varchar(100) Varchar(20) Varchar(20) Varchar(20) Varchar(10) Varchar(4) Varchar(4) Varchar(20) Varchar(20) Varchar(20) Varchar(20) Varchar(10) Varchar(4) Varchar(4) Varchar(20) Varchar(20) Varchar(20) Varchar(20) Varchar(20) 数据表及数据源

TC 授课表 Course_ID Tea_ID Varchar(20) Varchar(20)

数据库创建完成后,新建一个名为SIMS的数据源,不会建数据源的同学可以在去搜索创建数据源的详细步骤,这里的数据名称一定要为SIMS,否则在以后程序连接数据库的语句中会出现错误。 二、

操作演示

三、

代码部分

创建Java工程,创建名称为SIMS的包,一下Java类均包含在一个包内。

1. 登录界面

package SIMS;

import javax.swing.*; import java.awt.*;

import java.awt.event.*; import java.sql.*;

import java.text.SimpleDateFormat; import java.util.*; import java.util.Date;

public class login extends JFrame implements ActionListener{

String userID; //保留用户输入ID

String password; //保留用户输入password

JLabel jlID=new JLabel(\"用户 ID:\"); //使用文本创建标签对象 JLabel jlPwd=new JLabel(\"密 码:\");

JTextField jtID=new JTextField(); //创建ID输入框

JPasswordField jpPwd=new JPasswordField(); //创建密码输入框

ButtonGroup bg=new ButtonGroup(); //创建ButtonGroup组件对象

JPanel jp=new JPanel(); //创建Panel容器 JLabel jl=new JLabel();

JRadioButton jrb1=new JRadioButton(\"管理员\"); JRadioButton jrb2=new JRadioButton(\"教师\"); JRadioButton jrb3=new JRadioButton(\"学生\ JButton jb1=new JButton(\"登录\"); JButton jb2=new JButton(\"重置\");

public login(){

this.setLayout(null); this.setTitle(\"学生信息管理系统\"); this.setBounds(200,150,500,300);

this.setVisible(true); this.setResizable(false);

jlID.setBounds(150,60,100,20); jtID.setBounds(220,60,100,20); jlPwd.setBounds(150,90,100,20); jpPwd.setBounds(220,90,100,20); jp.setBounds(35,120,400,250); jb1.setBounds(160,170,60,20); jb2.setBounds(250,170,60,20); jb1.addActionListener(this); jb2.addActionListener(this);

jl.setBounds(340,75,130,20); bg.add(jrb1); bg.add(jrb2); bg.add(jrb3); this.add(jlID); this.add(jlPwd); this.add(jtID); this.add(jpPwd); this.add(jb1); this.add(jb2); this.add(jl); jp.add(jrb1); jp.add(jrb2);

jp.add(jrb3);

//设置窗口布局管理器 //设置窗口标题

//设置主窗体位置大小和可见性 //设置窗口的可见性 //设置ID框属性 //设置ID输入框属性 //设置密码框属性

//设置密码输入框属性 //设置JPanel容器属性

//设置登录按钮属性

//设置取消按钮属性 //设置登录按钮监听器 //设置取消按钮监听器 //设置提示框属性

//将所有空间加入窗体

}

this.add(jp);

centerShell(this);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) );

}

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){

return true; }

if(obj instanceof String) { String str = (String)obj; return str.equals(userID); }

return false; }

public void actionPerformed(ActionEvent e){

userID=jtID.getText(); //获取用户输入ID

password=jpPwd.getText(); //获取用户输入密码 if(e.getSource()==jb1){ //处理登录事件 if(userID.equals(\"\") || password.equals(\"\")){

jl.setFont(new Font(\"red\ //设置提示字体 jl.setForeground(Color.red); jl.setText(\"请输入用户ID和密码\");

}

else{ Connection con=null; try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\

//获取连接字符串

Statement stat=con.createStatement();

if(jrb1.isSelected()) {

//如果登录选中的管理员

ResultSet rs=stat.executeQuery(\"select * from Admin\");

//判断输入用户名是否存在 int flag=0;

while(rs.next()){ if(rs.getString(1).equals(userID)){

}

flag=1; break;

}

if(flag==0){

jl.setFont(new Font(\"red\

//设置提示字体

jl.setForeground(Color.red); jl.setText(\"用户ID不存在\"); }

if(flag==1){

ResultSet rss=stat.executeQuery(\"select Admin_Pwd,Admin_Name from Admin where Admin_ID='\"+userID+\"'\"); //从表Admin获取信息

while(rss.next()){ String str=rss.getString(1);

if(str.equals(password)){ }

new admin(rss.getString(2)); this.dispose(); //释放窗体

//创建admin窗口

//设置提示字体

else{ jl.setFont(new Font(\"red\

}

}

jl.setForeground(Color.red); }

jl.setText(\"密码错误\");

} else if(jrb2.isSelected()) {

ResultSet rs=stat.executeQuery(\"select * from Teacher_Info\"); int flag=0; while(rs.next()){

if(rs.getString(1).equals(userID)){ flag=1; }

break;

//判断输入用户名是否存在

}

if(flag==0){ jl.setFont(new Font(\"red\ jl.setForeground(Color.red);

jl.setText(\"用户ID不存在\");

//设置提示字体

}

if(flag==1){

ResultSet rss=stat.executeQuery(\"select Tea_Pwd,Tea_Names from Teacher_Info where Tea_ID='\"+userID+\"'\"); //从表Teacher_Info获取信息 while(rss.next()){ String str=rss.getString(1);

}

if(str.equals(password)){ }

else{ jl.setFont(new Font(\"red\ jl.setForeground(Color.red); }

jl.setText(\"密码错误\");

//创建admin窗口

new teacher(rss.getString(2),userID); this.dispose(); //释放窗体

//设置提示字体

}

}

else if(jrb3.isSelected()) { ResultSet rs=stat.executeQuery(\"select * from Student_Info\");

//判断输入用户名是否存在

int flag=0;

while(rs.next()){ if(rs.getString(1).equals(userID)){

}

flag=1; break;

}

if(flag==0){

jl.setFont(new Font(\"red\

//设置提示字体

jl.setForeground(Color.red); jl.setText(\"用户ID不存在\"); }

if(flag==1){

ResultSet rsss=stat.executeQuery(\"select Stu_Pwd,Stu_Name from Student_Info where Stu_ID='\"+userID+\"'\"); //从表Student_Info获取信息 while(rsss.next()){

}

}

String str=rsss.getString(1); if(str.equals(password)){

//创建admin窗口

new student(rsss.getString(2),userID); this.dispose(); //释放窗体

} else{

//设置提示字体

jl.setFont(new Font(\"red\

jl.setForeground(Color.red); }

jl.setText(\"密码错误\");

} }

catch(Exception ex){

}

}

ex.getStackTrace();

}finally{ try{ con.close(); }catch(Exception exc){ }

}

exc.printStackTrace();

else if(e.getSource()==jb2){ //处理登录事件 }

jtID.setText(\"\"); jpPwd.setText(\"\"); jrb3.setSelected(true); jl.setText(\"\");

}

public static void main(String[] args){ } }

new login();

2. 添加课程

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*; import java.awt.event.*;

public class add_course extends JFrame implements ActionListener{ static add_course ss;

String courseID=\"\"; //课程名 String coursename=\"\"; //课程名 String count=\"\";

//课时

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note1=new JLabel(\"*\");

JLabel note2=new JLabel(\"*\");

JLabel jlcourseID=new JLabel(\"课 程 号:\"); //使用文本框创建标签对象

JLabel jlcoursename=new JLabel(\"课 程 名:\"); JLabel jlcount=new JLabel(\"课 时:\");

JTextField jtcourseID=new JTextField(); //创建文本框对象 JTextField jtcoursename=new JTextField(); JTextField jtcount=new JTextField();

JButton submit=new JButton(\"添加\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public add_course(){ //添加教师账号信息 this.setTitle(\"添加课程信息\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器

this.add(jlcourseID); //将控件添加 到窗体 this.add(title); this.add(jlcoursename); this.add(jlcount);

this.add(jtcourseID); this.add(jtcoursename); this.add(jtcount);

this.add(note1); this.add(note2);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体 title.setForeground(Color.red);

note1.setFont(new Font(\"red\ //设置提示字体 note1.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体

warning.setForeground(Color.red);

title.setText(\"添 加 课 程 信 息\"); //设置控件及窗体

位置大小

title.setBounds(222,20,150,20); jlcourseID.setBounds(180,80,100,20); jlcoursename.setBounds(180,140,100,20); jlcount.setBounds(180,200,100,20); }

jtcourseID.setBounds(250,80,140,20); jtcoursename.setBounds(250,140,140,20); jtcount.setBounds(250,200,140,20);

note1.setBounds(400,80,140,20); note2.setBounds(400,140,140,20);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,140,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){ }

return true;

if(obj instanceof String) { String str = (String)obj; return str.equals(courseID); }

return false; }

public void actionPerformed(ActionEvent e){ courseID=jtcourseID.getText(); //获取用户输入内容 coursename=jtcoursename.getText();

count=jtcount.getText();

int temp=0,flag=0; Connection con=null;

if(e.getSource()==submit){

//判断是否已输入必填信息

if(courseID.equals(\"\") || coursename.equals(\"\")){ warning.setText(\"请输入必填信息\"); } else{

try{

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Course_ID from Course\"); while(rs.next()){ if(rs.getString(1).equals(courseID)){ }

}

warning.setText(\"课程ID已存在\");

flag=1; //判断用户名唯一 break;

if(flag!=1){ if(!count.equals(\"\")){ temp=stat.executeUpdate(\"insert into

Course(Course_ID,Course_Name,Course_Count)

values('\"+courseID+\"','\"+coursename+\"','\"+count+\"')\");

} else{ temp=stat.executeUpdate(\"insert into

Course(Course_ID,Course_Name) values('\"+courseID+\"','\"+coursename+\"')\");

}

}

}

if(temp==1){ }

else{ JOptionPane.showMessageDialog(ss,\"添加失败\");

JOptionPane.showMessageDialog(ss,\"添加成功\");

warning.setText(\"\");

} }catch(Exception ex){ }

ex.getStackTrace();

}

}else if(e.getSource()==reset){ }

warning.setText(\"\"); jtcourseID.setText(\"\"); jtcoursename.setText(\"\"); jtcount.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); } }

3. 添加学生

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*; import java.awt.event.*;

public class add_student extends JFrame implements ActionListener{

static add_teacher ss;

String userID=\"\"; String pwd1=\"\";

//用户名 //密码

String pwd2=\"\"; //确认密码

String getsdept=\"\"; //院系 String name=\"\"; //姓名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note1=new JLabel(\"*\"); JLabel note2=new JLabel(\"*\"); JLabel note3=new JLabel(\"*\");

JLabel jlID=new JLabel(\"学 号:\"); JLabel jlName=new JLabel(\"姓 名:\"); JLabel jlPwd=new JLabel(\"密 码:\"); JLabel jlPwd2=new JLabel(\"确认密码:\"); JLabel sdept=new JLabel(\"学 院:\");

JTextField jtID=new JTextField(); JTextField jtName=new JTextField();

JPasswordField jtPwd=new JPasswordField (); JPasswordField jtPwd2=new JPasswordField (); JTextField jtsdept=new JTextField();

JButton submit=new JButton(\"添加\"); JButton reset=new JButton(\"重置\");

public add_student(){ this.setTitle(\"添加学生账号信息\"); this.setLayout(null); this.add(jlID);

this.add(title); this.add(jlName); this.add(jlPwd); this.add(jlPwd2); this.add(sdept);

this.add(jtID); this.add(jtName); this.add(jtPwd); this.add(jtPwd2); this.add(jtsdept);

this.add(note1); this.add(note2);

this.add(note3);

//创建文本框对象 //创建按钮对象 //设置窗口标题 //设置窗口布局管理器//将控件添加 到窗体

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

title.setForeground(Color.red);

note1.setFont(new Font(\"red\ //设置提示字体 note1.setForeground(Color.red);

note2.setFont(new Font(\"red\ note2.setForeground(Color.red);

note3.setFont(new Font(\"red\ note3.setForeground(Color.red);

warning.setFont(new Font(\"red\ warning.setForeground(Color.red);

title.setText(\"添加学生账号信息\"); title.setBounds(222,20,150,20); jlID.setBounds(180,60,100,20);

jlName.setBounds(180,100,100,20); jlPwd.setBounds(180,140,100,20); jlPwd2.setBounds(180,180,100,20); sdept.setBounds(180,220,100,20);

jtID.setBounds(250,60,140,20);

jtName.setBounds(250,100,140,20); jtPwd.setBounds(250,140,140,20); jtPwd2.setBounds(250,180,140,20); jtsdept.setBounds(250,220,140,20);

note1.setBounds(400,60,140,20); note2.setBounds(400,140,140,20); note3.setBounds(400,180,140,20);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,100,150,20);

submit.addActionListener(this); reset.addActionListener(this);

this.setSize(600,400);

//设置提示字体 //设置提示字体 //设置提示字体 }

centerShell(this);

this.setVisible(true);

this.setResizable(false); //设置窗体不可变大小 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等

if(obj==null) return false;

return true;

if(this == obj){ }

if(obj instanceof String) { String str = (String)obj; return str.equals(pwd1); }

return false; }

public void actionPerformed(ActionEvent e){ userID=jtID.getText(); //获取用户输入内容

pwd1=jtPwd.getText(); pwd2=jtPwd2.getText(); getsdept=jtsdept.getText(); name=jtName.getText(); int temp=0,flag=0; Connection con=null;

if(e.getSource()==submit){ if(userID.equals(\"\") || pwd1.equals(\"\") || pwd2.equals(\"\")){ //判断是否已输入必填信息

}

warning.setText(\"请输入必填信息\");

else if(!pwd1.equals(pwd2)){ //判断两次输入密码是否相同

}

warning.setText(\"两次输入密码不相同\");

else{

try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Stu_ID from Student_Info\"); while(rs.next()){

符串

if(rs.getString(1).equals(userID)){ }

warning.setText(\"用户ID已存在\");

flag=1; //判断用户名唯一 break;

}

if(flag!=1){

if(!name.equals(\"\") && !getsdept.equals(\"\")){ temp=stat.executeUpdate(\"insert into

Student_Info(Stu_ID,Stu_Name,Stu_Pwd,Depart)

values('\"+userID+\"','\"+name+\"','\"+pwd1+\"','\"+getsdept+\"')\");

}

else if(!name.equals(\"\") && getsdept.equals(\"\")){

temp=stat.executeUpdate(\"insert into

Student_Info(Stu_ID,Stu_Name,Stu_Pwd) values('\"+userID+\"','\"+name+\"','\"+pwd1+\"')\");

}

else if(name.equals(\"\") && !getsdept.equals(\"\")){ temp=stat.executeUpdate(\"insert into

Student_Info(Stu_ID,Stu_Pwd,Depart) values('\"+userID+\"','\"+pwd1+\"','\"+getsdept+\"')\");

} else{ temp=stat.executeUpdate(\"insert into Student_Info(Stu_ID,Stu_Pwd) values('\"+userID+\"','\"+pwd1+\"')\"); }

}

if(temp==1){ }

else{ JOptionPane.showMessageDialog(ss,\"添加失败\"); }

JOptionPane.showMessageDialog(ss,\"添加成功\");

}catch(Exception ex){ ex.getStackTrace(); }

}

}else if(e.getSource()==reset){ //重置所有控件

warning.setText(\"\"); jtID.setText(\"\"); jtName.setText(\"\"); jtPwd.setText(\"\"); jtPwd2.setText(\"\");

jtsdept.setText(\"\");

} }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

//public static void main(String args[]){ // new add_student(); //} }

4. 添加教师

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class add_teacher extends JFrame implements ActionListener{

static add_teacher ss;

String userID=\"\"; //用户名 String pwd1=\"\"; //密码 String pwd2=\"\"; //确认密码

String getsdept=\"\"; //院系

String name=\"\"; //姓名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel(); JLabel note1=new JLabel(\"*\"); JLabel note2=new JLabel(\"*\"); JLabel note3=new JLabel(\"*\");

JLabel jlID=new JLabel(\"教 工 号:\"); JLabel jlName=new JLabel(\"姓 名:\"); JLabel jlPwd=new JLabel(\"密 码:\"); JLabel jlPwd2=new JLabel(\"确认密码:\");

JLabel sdept=new JLabel(\"学 院:\");

JTextField jtID=new JTextField(); JTextField jtName=new JTextField();

JPasswordField jtPwd=new JPasswordField (); JPasswordField jtPwd2=new JPasswordField (); JTextField jtsdept=new JTextField();

JButton submit=new JButton(\"添加\"); JButton reset=new JButton(\"重置\");

public add_teacher(){ this.setTitle(\"添加教师账号信息\"); this.setLayout(null); this.add(jlID); this.add(title); this.add(jlName); this.add(jlPwd); this.add(jlPwd2); this.add(sdept);

this.add(jtID); this.add(jtName); this.add(jtPwd); this.add(jtPwd2); this.add(jtsdept);

this.add(note1); this.add(note2); this.add(note3);

//使用文本框创建标签对象//创建文本框对象 //创建按钮对象 //添加教师账号信息 //设置窗口标题

//设置窗口布局管理器 //将控件添加 到窗体

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体 title.setForeground(Color.red);

note1.setFont(new Font(\"red\ //设置提示字体 note1.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

note3.setFont(new Font(\"red\ //设置提示字体 note3.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"添加教师账号信息\"); //设置控件及窗体位置大小

title.setBounds(222,20,150,20);

jlID.setBounds(180,60,100,20);

jlName.setBounds(180,100,100,20); jlPwd.setBounds(180,140,100,20); jlPwd2.setBounds(180,180,100,20); sdept.setBounds(180,220,100,20);

jtID.setBounds(250,60,140,20);

jtName.setBounds(250,100,140,20); jtPwd.setBounds(250,140,140,20); jtPwd2.setBounds(250,180,140,20); jtsdept.setBounds(250,220,140,20);

note1.setBounds(400,60,140,20); note2.setBounds(400,140,140,20); note3.setBounds(400,180,140,20);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,100,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

}

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等

if(obj==null)

return false; return true;

if(this == obj){ }

if(obj instanceof String) { String str = (String)obj; return str.equals(pwd1); }

return false; }

public void actionPerformed(ActionEvent e){ userID=jtID.getText(); //获取用户输入内容 pwd1=jtPwd.getText(); pwd2=jtPwd2.getText();

getsdept=jtsdept.getText(); name=jtName.getText();

int temp=0,flag=0; Connection con=null;

if(e.getSource()==submit){ //判断是否已输入必填信息 if(userID.equals(\"\") || pwd1.equals(\"\") || pwd2.equals(\"\")){

}

warning.setText(\"请输入必填信息\");

否一致

else if(!pwd1.equals(pwd2)){ //判断两次输入密码是

warning.setText(\"两次输入密码不相同\");

} else{

try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

符串

ResultSet rs=stat.executeQuery(\"select Tea_ID from Teacher_Info\"); while(rs.next()){ if(rs.getString(1).equals(userID)){ warning.setText(\"用户ID已存在\"); flag=1; //判断用户名唯一

}

break;

}

if(flag!=1){

if(!name.equals(\"\") && !getsdept.equals(\"\")){

temp=stat.executeUpdate(\"insert into

Teacher_Info(Tea_ID,Tea_Names,Tea_Pwd,Depart)

values('\"+userID+\"','\"+name+\"','\"+pwd1+\"','\"+getsdept+\"')\"); }

else if(!name.equals(\"\") && getsdept.equals(\"\")){

temp=stat.executeUpdate(\"insert into

Teacher_Info(Tea_ID,Tea_Names,Tea_Pwd) values('\"+userID+\"','\"+name+\"','\"+pwd1+\"')\");

}

else if(name.equals(\"\") && !getsdept.equals(\"\")){

temp=stat.executeUpdate(\"insert into

Teacher_Info(Tea_ID,Tea_Pwd,Depart) values('\"+userID+\"','\"+pwd1+\"','\"+getsdept+\"')\"); } else{ temp=stat.executeUpdate(\"insert into Teacher_Info(Tea_ID,Tea_Pwd) values('\"+userID+\"','\"+pwd1+\"')\");

}

} }

if(temp==1){

JOptionPane.showMessageDialog(ss,\"添加成功\");

} else{ }

JOptionPane.showMessageDialog(ss,\"添加失败\");

}catch(Exception ex){ ex.getStackTrace(); }

}else if(e.getSource()==reset){

warning.setText(\"\"); jtID.setText(\"\");

}

}

jtName.setText(\"\"); jtPwd.setText(\"\"); jtPwd2.setText(\"\"); jtsdept.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); } // //

public static void main(String[] args){ new add_teacher();

// } }

5. 添加授课信息 package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class add_tc extends JFrame implements ActionListener{

static add_tc ss;

String courseID=\"\"; //课程名 String teachername=\"\"; //课程名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel(); JLabel note1=new JLabel(\"*\"); JLabel note2=new JLabel(\"*\");

JLabel jlcourseID=new JLabel(\"课 程 号:\"); //使用文本框创建标签对象

JLabel jlteachername=new JLabel(\"教 师 号:\");

JTextField jtcourseID=new JTextField(); //创建文本框对象 JTextField jtteachername=new JTextField();

JButton submit=new JButton(\"添加\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public add_tc(){ //添加授课信息

this.setTitle(\"添加授课信息\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器 this.add(jlcourseID); //将控件添加 到窗体 this.add(jlteachername); this.add(title); this.add(jtcourseID); this.add(jtteachername);

this.add(note1); this.add(note2);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

title.setForeground(Color.red);

note1.setFont(new Font(\"red\ //设置提示字体 note1.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"添 加 授 课 信 息\"); //设置控件及窗体位置大小

title.setBounds(222,20,150,20); jlcourseID.setBounds(180,80,100,20); }

jlteachername.setBounds(180,140,100,20);

jtcourseID.setBounds(250,80,140,20);

jtteachername.setBounds(250,140,140,20);

note1.setBounds(400,80,140,20); note2.setBounds(400,140,140,20);

submit.setBounds(200,250,60,20); reset.setBounds(300,250,60,20);

warning.setBounds(420,140,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){ }

return true;

if(obj instanceof String) { String str = (String)obj; return str.equals(courseID); }

return false; }

public void actionPerformed(ActionEvent e){ courseID=jtcourseID.getText(); //获取用户输入内容 teachername=jtteachername.getText();

符串

int temp=0,flag1=0,flag2=0,flag3=0; Connection con=null;

if(e.getSource()==submit){ //判断是否已输入必填信息 if(courseID.equals(\"\") || teachername.equals(\"\")){

}

warning.setText(\"请输入必填信息\");

else{ try{

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Course_ID from Course\"); while(rs.next()){ if(rs.getString(1).equals(courseID)){ }

}

flag1=1; //判断课程ID存在 break;

Teacher_Info\");

ResultSet rss=stat.executeQuery(\"select Tea_ID from while(rss.next()){

if(rss.getString(1).equals(teachername)){ }

flag2=1; //判断教师ID存在 break;

}

if(flag1!=1){

warning.setText(\"课程ID不存在\"); }else if(flag2!=1){ }

ResultSet rsss=stat.executeQuery(\"select Course_ID,Tea_ID from while(rsss.next()){ if(rsss.getString(1).equals(courseID) &&

warning.setText(\"教师ID不存在\");

tc\");

rsss.getString(2).equals(teachername)){ flag3=1; warning.setText(\"授课信息重复\");

}

}

if(flag1==1 && flag2==1 &&flag3!=1){ temp=stat.executeUpdate(\"insert into

TC(Course_ID,Tea_ID) values('\"+courseID+\"','\"+teachername+\"')\");

} }

if(temp==1){ JOptionPane.showMessageDialog(ss,\"添加成功\"); } else{ }

JOptionPane.showMessageDialog(ss,\"添加失败\"); warning.setText(\"\");

}catch(Exception ex){

ex.getStackTrace();

}

}

}else if(e.getSource()==reset){ }

warning.setText(\"\"); jtcourseID.setText(\"\"); jtteachername.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); } //

public static void main(String args[]){

// // }

}

new add_tc();

6. 管理员界面 package SIMS;

import javax.swing.*;

import java.sql.*;

import java.text.SimpleDateFormat; import java.util.Date; import java.awt.*; import java.awt.event.*; import java.awt.Toolkit;

public class admin extends JFrame implements ActionListener{

JTextArea theArea=null; //创建菜单栏 JMenuBar MBar=new JMenuBar(); JPanel panel=new JPanel(); JLabel hello=new JLabel();

JButton exit=new JButton(\"退 出 登 录\");

JMenu add=new JMenu(\"增加信息\"); JMenu delete=new JMenu(\"删除信息\"); JMenu change=new JMenu(\"修改信息\"); JMenu search=new JMenu(\"查询信息\");

JMenuItem add_teacher=new JMenuItem(\"教师信息\"); //创建二级菜单 JMenuItem add_student=new JMenuItem(\"学生信息\"); JMenuItem add_course=new JMenuItem(\"课程信息\"); JMenuItem det_teacher=new JMenuItem(\"教师信息\"); JMenuItem det_student=new JMenuItem(\"学生信息\"); JMenuItem det_course=new JMenuItem(\"课程信息\"); JMenuItem cha_teacher=new JMenuItem(\"教师密码\"); JMenuItem cha_student=new JMenuItem(\"学生密码\"); JMenuItem cha_course=new JMenuItem(\"课程信息\"); JMenuItem sea_teacher=new JMenuItem(\"教师信息\"); JMenuItem sea_student=new JMenuItem(\"学生信息\"); JMenuItem sea_course=new JMenuItem(\"课程信息\"); JMenuItem add_tc=new JMenuItem(\"授课信息\");

public admin(String name){ add_teacher.addActionListener(this); add_student.addActionListener(this);

add_course.addActionListener(this); det_teacher.addActionListener(this); det_student.addActionListener(this); det_course.addActionListener(this); cha_course.addActionListener(this); cha_student.addActionListener(this); cha_teacher.addActionListener(this); sea_teacher.addActionListener(this); sea_student.addActionListener(this); sea_course.addActionListener(this); add_tc.addActionListener(this);

add.add(add_teacher); //添加二级菜单内容 add.add(add_student); add.add(add_course); add.add(add_tc); delete.add(det_teacher); delete.add(det_student); delete.add(det_course); change.add(cha_teacher); change.add(cha_student); change.add(cha_course); search.add(sea_teacher); search.add(sea_student); search.add(sea_course);

MBar.add(add); //将菜单添加至菜单栏 MBar.add(delete); MBar.add(change);

MBar.add(search);

setJMenuBar(MBar); //添加菜单

hello.setBounds(20,50,300,200); exit.setBounds(220,160,140,20);

panel.setBounds(10,100,550,320);

hello.setFont(new Font(\"\ //设置提示字体 hello.setForeground(Color.blue);

hello.setText(\"欢迎管理员 \\\"\"+name+\"\\\" 登录\"); //显示登

录者身份提示

panel.add(hello); this.add(exit);

this.add(panel);

exit.addActionListener(this); //添加退出按钮动作监听器

this.setTitle(\"管理员界面\"); this.setLayout(null);

this.setResizable(false); //设置窗体大小不可变

this.setSize(600,400); //设置窗体大小 centerShell(this); //窗体在屏幕中间显示 this.setVisible(true); //设置窗体可见 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/* JTextArea theArea=new JTextArea(); //添加文本显示区域 theArea.setEditable(true);

getContentPane().setLayout(new BorderLayout());

getContentPane().add(new JScrollPane(theArea),BorderLayout.CENTER); */ }

public void actionPerformed(ActionEvent e){ //动作监听事件 if(e.getSource()==add_teacher){

new add_teacher();

}else if(e.getSource()==add_student){ new add_student(); }else if(e.getSource()==exit){ this.dispose(); new login();

}else if(e.getSource()==add_course){ new add_course();

}else if(e.getSource()==det_teacher){ new det_teacher();

}else if(e.getSource()==det_student){

new det_student();

}else if(e.getSource()==det_course){ new det_course(); }else if(e.getSource()==cha_teacher){ new cha_teacher(); }else if(e.getSource()==cha_student){ new cha_student();

}else if(e.getSource()==cha_course){

}

new cha_course();

}else if(e.getSource()==sea_teacher){ new sea_teacher();

}else if(e.getSource()==sea_student){ new sea_student(); }else if(e.getSource()==sea_course){ new sea_course(); }else if(e.getSource()==add_tc){ new add_tc(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

//public static void main(String[] args){ // new admin(\"QQ\"); //} }

7. 管理员更改课程

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class cha_course extends JFrame implements ActionListener{

static cha_course ss;

String courseID=\"\"; //课程ID String coursename=\"\";

JLabel title=new JLabel(); JLabel note1=new JLabel(\"*\"); JLabel note2=new JLabel(\"*\"); JLabel note3=new JLabel(\"*\");

//课程名

JLabel warning=new JLabel(); //输入信息提示框

JLabel jlID=new JLabel(\"课 程 号:\"); //使用文本框创建标签对象 JLabel jlPwd2=new JLabel(\"课 程 名:\");

JTextField jtcourseID=new JTextField(); //创建文本框对象 JTextField jtcoursename=new JTextField();

JButton submit=new JButton(\"修改\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public cha_course(){ //添加教师账号信息

this.setTitle(\"修改课程信息\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器 this.add(jlID); //将控件添加 到窗体 this.add(title); this.add(jlPwd2);

this.add(jtcourseID); this.add(jtcoursename);

this.add(note1); this.add(note2); this.add(note3);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

title.setForeground(Color.red);

note1.setFont(new Font(\"red\ //设置提示字体 note1.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"修 改 课 程 信 息\"); //设置控件及窗体位置大小

title.setBounds(240,40,150,20); }

public void actionPerformed(ActionEvent e){ courseID=jtcourseID.getText(); //获取用户输入内容

coursename=jtcoursename.getText();

int temp=0,flag1=0; Connection con=null;

if(e.getSource()==submit){ jlID.setBounds(180,100,100,20); jlPwd2.setBounds(180,170,100,20);

jtcourseID.setBounds(250,100,140,20); jtcoursename.setBounds(250,170,140,20);

note1.setBounds(400,100,140,20); note2.setBounds(400,170,140,20);

submit.setBounds(200,270,60,20);

reset.setBounds(300,270,60,20);

warning.setBounds(420,100,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

//判断是否已输入必填信息

if(courseID.equals(\"\") || coursename.equals(\"\")){ warning.setText(\"请输入必填信息\"); } else{ try{

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Course_ID from Course\"); while(rs.next()){ }

if(rs.getString(1).equals(courseID)){ }

flag1=1; //判断课程存在 break;

符串

if(flag1!=1){ warning.setText(\"课程不存在\"); } else{

temp=stat.executeUpdate(\"update Course set Course_Name='\"+coursename+\"' where Course_ID='\"+courseID+\"'\"); } if(temp==1){ }

}

JOptionPane.showMessageDialog(ss,\"修改课程信息成功\");

warning.setText(\"\"); } else{ }

JOptionPane.showMessageDialog(ss,\"修改课程信息失败\");

}catch(Exception ex){ }

ex.getStackTrace();

}else if(e.getSource()==reset){ warning.setText(\"\"); }

jtcourseID.setText(\"\"); jtcoursename.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight;

if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

//public static void main(String[] args){ // new cha_course(); //} }

8. 管理员更改学生

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*; import java.awt.event.*;

public class cha_student extends JFrame implements ActionListener{

static cha_student ss;

String userID=\"\"; //用户名 String pwd1=\"\"; String pwd2=\"\";

//密码

//确认密码

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note1=new JLabel(\"*\"); JLabel note2=new JLabel(\"*\");

JLabel note3=new JLabel(\"*\");

JLabel jlID=new JLabel(\"学 号:\"); //使用文本框创建标签对象

JLabel jlPwd=new JLabel(\"密 码:\"); JLabel jlPwd2=new JLabel(\"确认密码:\");

JTextField jtID=new JTextField(); //创建文本框对象 JPasswordField jtPwd=new JPasswordField (); JPasswordField jtPwd2=new JPasswordField ();

JButton submit=new JButton(\"添加\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public cha_student(){ //添加教师账号信息 this.setTitle(\"修改学生信息\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器 this.add(jlID); //将控件添加 到窗体 this.add(title); this.add(jlPwd); this.add(jlPwd2);

this.add(jtID); this.add(jtPwd); this.add(jtPwd2);

this.add(note1); this.add(note2); this.add(note3);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

title.setForeground(Color.red);

note1.setFont(new Font(\"red\ //设置提示字体 note1.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

note3.setFont(new Font(\"red\ //设置提示字体 note3.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体

warning.setForeground(Color.red);

title.setText(\"修 改 学 生 密 码\"); //设置控件及窗体位置大小

title.setBounds(240,30,150,20); }

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null)

return false;

if(this == obj){ return true; }

if(obj instanceof String) { String str = (String)obj; return str.equals(pwd1); }

jlID.setBounds(180,90,100,20); jlPwd.setBounds(180,140,100,20); jlPwd2.setBounds(180,190,100,20);

jtID.setBounds(250,90,140,20); jtPwd.setBounds(250,140,140,20); jtPwd2.setBounds(250,190,140,20);

note1.setBounds(400,90,140,20); note2.setBounds(400,140,140,20); note3.setBounds(400,190,140,20);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,90,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

return false;

}

public void actionPerformed(ActionEvent e){ userID=jtID.getText(); //获取用户输入内容

pwd1=jtPwd.getText(); pwd2=jtPwd2.getText();

int temp=0,flag=0; Connection con=null; if(e.getSource()==submit){

}

//判断是否已输入必填信息

if(userID.equals(\"\") || pwd1.equals(\"\") || pwd2.equals(\"\")){

warning.setText(\"请输入必填信息\");

否一致

else if(!pwd1.equals(pwd2)){ //判断两次输入密码是 warning.setText(\"两次输入密码不相同\"); } else{

try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Stu_ID from Student_Info\"); while(rs.next()){ if(rs.getString(1).equals(userID)){

}

flag=1; //判断用户名唯一 break;

符串

}

if(flag!=1){ }

warning.setText(\"学生账号不存在\");

else{ temp=stat.executeUpdate(\"update Student_Info set }

if(temp==1){

JOptionPane.showMessageDialog(ss,\"修改密码成功\");

Stu_Pwd='\"+pwd1+\"' where Stu_ID='\"+userID+\"'\");

} else{ JOptionPane.showMessageDialog(ss,\"修改密码失败\");

}

}

}catch(Exception ex){ ex.getStackTrace(); }

}

}else if(e.getSource()==reset){ }

warning.setText(\"\"); jtID.setText(\"\"); jtPwd.setText(\"\"); jtPwd2.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); } // // // }

public static void main(String[] args){ new cha_teacher(); }

9. 管理员更改教师

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class cha_teacher extends JFrame implements ActionListener{

static cha_teacher ss;

String userID=\"\"; //用户名 String pwd1=\"\"; String pwd2=\"\";

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel(); JLabel note1=new JLabel(\"*\"); JLabel note2=new JLabel(\"*\"); JLabel note3=new JLabel(\"*\");

//密码

//确认密码

JLabel jlID=new JLabel(\"教 工 号:\"); //使用文本框创建标签对象 JLabel jlPwd=new JLabel(\"密 码:\"); JLabel jlPwd2=new JLabel(\"确认密码:\");

JTextField jtID=new JTextField(); //创建文本框对象 JPasswordField jtPwd=new JPasswordField (); JPasswordField jtPwd2=new JPasswordField ();

JButton submit=new JButton(\"添加\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public cha_teacher(){ //添加教师账号信息 this.setTitle(\"修改教师账号信息\"); //设置窗口标题 this.setLayout(null); //设置窗口布局管理器

this.add(jlID); //将控件添加 到窗体 this.add(title); this.add(jlPwd); this.add(jlPwd2);

this.add(jtID); this.add(jtPwd); this.add(jtPwd2);

this.add(note1); this.add(note2); this.add(note3);

this.add(submit);

this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

title.setForeground(Color.red);

note1.setFont(new Font(\"red\ //设置提示字体 note1.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

note3.setFont(new Font(\"red\ //设置提示字体 note3.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"修 改 教 师 密 码\"); //设置控件及窗体位置大小

title.setBounds(240,30,150,20); jlID.setBounds(180,90,100,20);

jlPwd.setBounds(180,140,100,20); jlPwd2.setBounds(180,190,100,20);

jtID.setBounds(250,90,140,20); jtPwd.setBounds(250,140,140,20); jtPwd2.setBounds(250,190,140,20);

note1.setBounds(400,90,140,20); note2.setBounds(400,140,140,20); note3.setBounds(400,190,140,20);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,90,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){ }

return true;

if(obj instanceof String) { String str = (String)obj; return str.equals(pwd1); }

return false; }

public void actionPerformed(ActionEvent e){ userID=jtID.getText(); //获取用户输入内容 pwd1=jtPwd.getText();

pwd2=jtPwd2.getText();

int temp=0,flag=0; Connection con=null;

if(e.getSource()==submit){ //判断是否已输入必填信息 if(userID.equals(\"\") || pwd1.equals(\"\") || pwd2.equals(\"\")){

}

warning.setText(\"请输入必填信息\");

否一致

else if(!pwd1.equals(pwd2)){ //判断两次输入密码是

warning.setText(\"两次输入密码不相同\");

} else{

try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Tea_ID from Teacher_Info\"); while(rs.next()){ }

if(rs.getString(1).equals(userID)){ flag=1; //判断用户名唯一 }

break;

符串

if(flag!=1){

warning.setText(\"教师账号不存在\"); } else{ temp=stat.executeUpdate(\"update Teacher_Info set

Tea_Pwd='\"+pwd1+\"' where Tea_ID='\"+userID+\"'\");

} }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

}

if(temp==1){ JOptionPane.showMessageDialog(ss,\"修改密码成功\"); } else{ }

JOptionPane.showMessageDialog(ss,\"修改密码失败\");

}catch(Exception ex){ }

ex.getStackTrace();

}else if(e.getSource()==reset){ warning.setText(\"\"); }

jtID.setText(\"\"); jtPwd.setText(\"\"); jtPwd2.setText(\"\");

// public static void main(String[] args){ // new cha_teacher(); // } }

10.删除课程

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class det_course extends JFrame implements ActionListener{

static det_course ss;

String courseID=\"\"; //用户名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note=new JLabel(\"(删除操作不可恢复,请谨慎操作)\");

JLabel jlteacherID=new JLabel(\"课程号:\"); //使用文本框创建标签对象

JTextField jtteacherID=new JTextField(); //创建文本框对象

JButton submit=new JButton(\"删除\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public det_course(){ //添加课程账号信息

this.setTitle(\"删除课程信息\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器 this.add(jlteacherID); //将控件添加 到窗体 this.add(title); this.add(note);

this.add(jtteacherID);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体 title.setForeground(Color.red);

note.setFont(new Font(\"\ //设置提示字体 note.setForeground(Color.blue);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"删除课程信息\"); //设置控件及窗体位置大小 title.setBounds(235,30,150,20); }

jlteacherID.setBounds(200,150,100,20); jtteacherID.setBounds(270,150,120,20); note.setBounds(190,80,220,30);

submit.setBounds(200,270,60,20);

reset.setBounds(300,270,60,20);

warning.setBounds(240,190,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器

reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等

if(obj==null) return false;

if(this == obj){ return true; }

if(obj instanceof String) { String str = (String)obj; return str.equals(courseID); }

return false; }

public void actionPerformed(ActionEvent e){

courseID=jtteacherID.getText(); //获取用户输入内容

Connection con=null; if(e.getSource()==submit){ if(courseID.equals(\"\")){

}

//判断是否已输入必填信息

warning.setText(\"请输入课程ID\");

try{

else{

int temp=0;

int flag1=0,flag2=0;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Course_ID from Course\");

while(rs.next()){ //判断课程ID是否存在 if(rs.getString(1).equals(courseID)){

flag1=1; break; }

符串

}

if(flag1!=1){ }

warning.setText(\"课程ID不存在\");

ResultSet rss=stat.executeQuery(\"select Course_ID from SC\"); while(rss.next()){

if(rss.getString(1).equals(courseID)) { }

flag2=1; break;

}

if(flag2==1){ }

warning.setText(\"有学生选修,不可删除\");

else if(flag1==1){ temp=stat.executeUpdate(\"delete from course where Course_ID='\"+courseID+\"'\");

}

}

}

}

if(temp==1){ JOptionPane.showMessageDialog(ss,\"删除成功\"); warning.setText(\"\"); } else{ }

ex.getStackTrace();

JOptionPane.showMessageDialog(ss,\"删除失败\");

}catch(Exception ex){

}else if(e.getSource()==reset){ warning.setText(\"\"); }

jtteacherID.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

//public static void main(String[] args){ // new det_course(); //} }

11.删除学生

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class det_student extends JFrame implements ActionListener{

static det_student ss;

String studentID=\"\"; //用户名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note=new JLabel(\"(删除操作不可恢复,请谨慎操作)\");

JLabel jlteacherID=new JLabel(\"学 号:\"); //使用文本框创建标签对象

JTextField jtteacherID=new JTextField(); //创建文本框对象

JButton submit=new JButton(\"删除\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public det_student(){ //添加教师账号信息

this.setTitle(\"删除学生账号信息\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器

this.add(jlteacherID); //将控件添加 到窗体 this.add(title); this.add(note);

this.add(jtteacherID);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体 title.setForeground(Color.red);

note.setFont(new Font(\"\ //设置提示字体 note.setForeground(Color.blue);

warning.setFont(new Font(\"red\ //设置提示字体

warning.setForeground(Color.red);

title.setText(\"删除学生账号信息\"); //设置控件及窗体位置大小

title.setBounds(222,30,150,20); }

jlteacherID.setBounds(200,150,100,20); jtteacherID.setBounds(270,150,120,20); note.setBounds(190,80,220,30);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(240,190,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){ }

return true;

if(obj instanceof String) { String str = (String)obj; return str.equals(studentID); }

return false; }

public void actionPerformed(ActionEvent e){ studentID=jtteacherID.getText(); //获取用户输入内容

Connection con=null;

符串

if(e.getSource()==submit){

//判断是否已输入必填信息

if(studentID.equals(\"\")){ warning.setText(\"请输入学生ID\"); } else{

try{ int temp1=0,temp2=0;

int flag1=0,flag2=0;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Stu_ID from Student_Info\");

while(rs.next()){ //判断学生ID是否存在 if(rs.getString(1).equals(studentID)){ }

flag1=1; break; }

if(flag1!=1){ warning.setText(\"学生ID不存在\"); }

ResultSet rss=stat.executeQuery(\"select Stu_ID from Stu_SC\"); while(rss.next()){

if(rss.getString(1).equals(studentID)) { flag2=1; }

break;

}

if(flag1==1){

temp1=stat.executeUpdate(\"delete from Student_Info where Stu_ID='\"+studentID+\"'\");

}

if(flag2==1){ temp2=stat.executeUpdate(\"delete from Stu_SC where

Stu_ID='\"+studentID+\"'\");

}

if(temp1==1){ JOptionPane.showMessageDialog(ss,\"删除成功\"); warning.setText(\"\");

}

}

}

}

else{ JOptionPane.showMessageDialog(ss,\"删除失败\"); }

}catch(Exception ex){ ex.getStackTrace(); }

}else if(e.getSource()==reset){

warning.setText(\"\"); jtteacherID.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

//public static void main(String[] args){ // new det_student(); //} }

12.删除教师

package SIMS;

import javax.swing.*;

import java.sql.*;

import java.awt.*;

import java.awt.event.*;

public class det_teacher extends JFrame implements ActionListener{

static det_teacher ss;

String teacherID=\"\"; //用户名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note=new JLabel(\"(删除操作不可恢复,请谨慎操作)\");

JLabel jlteacherID=new JLabel(\"教 工 号:\"); //使用文本框创建标签对象

JTextField jtteacherID=new JTextField(); //创建文本框对象

JButton submit=new JButton(\"删除\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public det_teacher(){ //添加教师账号信息 this.setTitle(\"删除教师账号信息\"); //设置窗口标题 this.setLayout(null); //设置窗口布局管理器 this.add(jlteacherID); //将控件添加 到窗体

this.add(title); this.add(note);

this.add(jtteacherID);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体 title.setForeground(Color.red);

note.setFont(new Font(\"\ //设置提示字体 note.setForeground(Color.blue);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"删除教师账号信息\"); //设置控件及窗体位置大小

title.setBounds(222,30,150,20);

}

jlteacherID.setBounds(200,150,100,20); jtteacherID.setBounds(270,150,120,20); note.setBounds(190,80,220,30);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(240,190,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){ return true; }

if(obj instanceof String) { String str = (String)obj;

return str.equals(teacherID); }

return false; }

public void actionPerformed(ActionEvent e){

teacherID=jtteacherID.getText(); //获取用户输入内容

//判断是否已输入必填信息

Connection con=null;

if(e.getSource()==submit){

if(teacherID.equals(\"\")){ warning.setText(\"请输入教师ID\"); } else{ try{

int temp=0;

int flag1=0,flag2=0,flag3=0;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select Tea_ID from Teacher_Info\");

while(rs.next()){ //判断教师ID是否存在

if(rs.getString(1).equals(teacherID)){ flag1=1; }

break;

符串

}

if(flag1!=1){

warning.setText(\"教师ID不存在\"); } else{ }

ResultSet rss=stat.executeQuery(\"select Tea_ID from Course\"); while(rss.next()){ }

if(rss.getString(1).equals(teacherID)){ warning.setText(\"教师有授课不可删除\"); flag2=1; //判断教师是否授课 break; }

Teacher_Info\");

ResultSet rsss=stat.executeQuery(\"select Class_ID from while(rsss.next()){ if(rsss.getString(1)!=null){ }

}

warning.setText(\"教师有管理班级不可删除\"); flag3=1; //判断教师是否管理break;

班级

if(flag1==1 && flag2!=1 && flag3!=1){

temp=stat.executeUpdate(\"delete from Teacher_Info where Tea_ID='\"+teacherID+\"'\"); }

}

if(temp==1){

JOptionPane.showMessageDialog(ss,\"删除成功\"); warning.setText(\"\"); } else{ }

JOptionPane.showMessageDialog(ss,\"删除失败\");

}catch(Exception ex){ }

ex.getStackTrace();

}else if(e.getSource()==reset){ warning.setText(\"\"); }

jtteacherID.setText(\"\");

}

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

//public static void main(String[] args){ // new det_teacher(); //} }

13.管理员查询课程

package SIMS;

import java.awt.BorderLayout; import java.awt.Color;

import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.lang.*;

public class sea_course extends JFrame implements ActionListener{

private JFrame frame = null; private JTable table = null;

private table_model_course model = null;

private JScrollPane s_pan = null; //滚动块 private JButton submit = null, reset = null; private JPanel pane = null;

public sea_course() {

frame = new JFrame(\"查询课程信息\"); pane = new JPanel();

submit = new JButton(\"查询数据\"); reset = new JButton(\"清除数据\");

pane.add(submit); pane.add(reset);

submit.addActionListener(this); reset.addActionListener(this);

model = new table_model_course(20);

table = new JTable(model){ 方法,设置表格中内容居中显示

//重写getCellRenderer

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(40); tcm.getColumn(2).setPreferredWidth(90); tcm.getColumn(3).setPreferredWidth(40); tcm.getColumn(4).setPreferredWidth(90);

s_pan = new JScrollPane(table);

//将表格加

入滚动框

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==submit){

removeData();

try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串

Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select

Course.Course_ID,Course_Name,Tea_Names,Course_Count from Course,Teacher_Info,TC where Course.Course_ID=TC.Course_ID and Teacher_Info.Tea_ID=TC.Tea_ID\");

while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)); }

}catch(Exception ex){ }

ex.getStackTrace();

}

if(e.getSource()==reset){ }

removeData();

}

private void addData(String id,String name,String sex,String sdept) { model.addRow(id,name,sex,sdept); table.updateUI();

}

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) );

}

// public static void main(String args[]) // {

// new sea_course(); // } }

14.管理员查询学生

package SIMS;

import java.awt.BorderLayout; import java.awt.Color;

import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;

import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.lang.*;

public class sea_student extends JFrame implements ActionListener{

private JFrame frame = null;

private JTable table = null;

private table_model_admin model = null;

private JScrollPane s_pan = null; //滚动块

private JButton submit = null, reset = null; private JPanel pane = null;

public sea_student() {

frame = new JFrame(\"查询学生信息\"); pane = new JPanel();

submit = new JButton(\"查询数据\"); reset = new JButton(\"清除数据\");

pane.add(submit); pane.add(reset);

submit.addActionListener(this); reset.addActionListener(this);

model = new table_model_admin(20);

table = new JTable(model){ 方法,设置表格中内容居中显示

//重写getCellRenderer

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(40); tcm.getColumn(2).setPreferredWidth(90); tcm.getColumn(3).setPreferredWidth(40); tcm.getColumn(4).setPreferredWidth(90);

s_pan = new JScrollPane(table);

//将表格加

入滚动框

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==submit){

removeData(); try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement(); ResultSet rs=stat.executeQuery(\"select

Stu_ID,Stu_Name,Stu_Sex,Depart from Student_Info\"); while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)); }

}catch(Exception ex){ ex.getStackTrace();

}

}

if(e.getSource()==reset){ removeData(); } }

private void addData(String id,String name,String sex,String sdept) { model.addRow(id,name,sex,sdept); table.updateUI(); }

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }

// public static void main(String args[]) { // new sea_student(); // } }

15.管理员查询教师

package SIMS;

import java.awt.BorderLayout; import java.awt.Color;

import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*;

import javax.swing.*;

import java.sql.*; import java.lang.*;

public class sea_teacher extends JFrame implements ActionListener{

private JFrame frame = null;

private JTable table = null;

private table_model_admin model = null; private JScrollPane s_pan = null; //滚动块 private JButton submit = null, reset = null; private JPanel pane = null;

public sea_teacher() {

frame = new JFrame(\"查询教师信息\"); pane = new JPanel();

submit = new JButton(\"查询数据\"); reset = new JButton(\"清除数据\");

pane.add(submit); pane.add(reset);

submit.addActionListener(this); reset.addActionListener(this);

model = new table_model_admin(20);

table = new JTable(model){ //重写getCellRenderer方法,设置表格中内容居中显示

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(40); tcm.getColumn(2).setPreferredWidth(90);

tcm.getColumn(3).setPreferredWidth(40); tcm.getColumn(4).setPreferredWidth(90);

s_pan = new JScrollPane(table);

//将表格加

入滚动框

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==submit){ removeData(); try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement(); ResultSet rs=stat.executeQuery(\"select

Tea_ID,Tea_Names,Tea_Sex,Depart from Teacher_Info\");

while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)); } }catch(Exception ex){

}

ex.getStackTrace();

}

if(e.getSource()==reset){ } }

private void addData(String id,String name,String sex,String sdept) { model.addRow(id,name,sex,sdept); table.updateUI(); }

private void removeData() {

removeData();

model.removeRows(0, model.getRowCount());

table.updateUI(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }

// public static void main(String args[]) { // new sea_teacher(); // } }

16.学生界面

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*; import java.awt.Toolkit;

public class student extends JFrame implements ActionListener{ String studentid=\"\";

JTextArea theArea=null; //创建菜单栏 JMenuBar MBar=new JMenuBar(); JPanel panel=new JPanel();

JLabel hello=new JLabel();

JButton exit=new JButton(\"退 出 登 录\");

JMenu change=new JMenu(\"修改信息\"); JMenu score=new JMenu(\"查看分数\"); JMenu course=new JMenu(\"选修课程\");

JMenuItem cha_student=new JMenuItem(\"账号信息\"); //创建二级菜单 JMenuItem cha_password=new JMenuItem(\"密码信息\"); JMenuItem score2=new JMenuItem(\"查看分数\"); JMenuItem course2=new JMenuItem(\"选修课程\");

public student(String name,String ID){

studentid=ID;

cha_student.addActionListener(this); cha_password.addActionListener(this); score2.addActionListener(this); course2.addActionListener(this);

change.add(cha_student); //添加二级菜单内容 change.add(cha_password); score.add(score2); course.add(course2);

MBar.add(change); //将菜单添加至菜单栏 MBar.add(score); MBar.add(course);

setJMenuBar(MBar); //添加菜单

hello.setBounds(20,50,300,200); exit.setBounds(220,160,140,20);

panel.setBounds(10,100,550,320);

hello.setFont(new Font(\"\ //设置提示字体 hello.setForeground(Color.blue);

hello.setText(\"欢迎学生 \\\"\"+name+\"\\\" 登录\"); //显示登录者身份提示

panel.add(hello);

this.add(exit);

this.add(panel);

exit.addActionListener(this); //添加退出按钮动

作监听器

this.setTitle(\"学生界面\"); this.setLayout(null); this.setResizable(false); //设置窗体大小不可变 this.setSize(600,400); //设置窗体大小

centerShell(this); //窗体在屏幕中间显示 this.setVisible(true); //设置窗体可见 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/* JTextArea theArea=new JTextArea(); //添加文本显示区域 theArea.setEditable(true);

getContentPane().setLayout(new BorderLayout());

getContentPane().add(new JScrollPane(theArea),BorderLayout.CENTER); */ }

public void actionPerformed(ActionEvent e){ //动作监听事件 if(e.getSource()==exit){ }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth)

this.dispose(); new login();

}else if(e.getSource()==cha_password){ new student_pwd(studentid); }else if(e.getSource()==cha_student){ new student_info(studentid); }else if(e.getSource()==score2){ new student_score(studentid); }else if(e.getSource()==course2){ new student_course(studentid); }

shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

// public static void main(String[] args){ // // }

}

new student(\"QQ\

17.学生选课

package SIMS;

import java.awt.BorderLayout; import java.awt.Color;

import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.lang.*;

public class student_course extends JFrame implements ActionListener{ String id=\"\";

static student_course ss;

private JFrame frame = null; private JTable table = null;

private table_model_student_course model = null; private JScrollPane s_pan = null; //滚动块 private JButton submit = null, reset = null; private JButton search=null; private JPanel pane = null;

public student_course(String studentid) { id=studentid;

frame = new JFrame(\"选修课程信息\"); pane = new JPanel();

search = new JButton(\"查询课程\"); reset = new JButton(\"清除数据\");

submit = new JButton(\"确认提交\");

pane.add(search); pane.add(reset); pane.add(submit);

search.addActionListener(this);

reset.addActionListener(this); submit.addActionListener(this);

model = new table_model_student_course(20);

table = new JTable(model){ 方法,设置表格中内容居中显示

//重写getCellRenderer

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(40);

tcm.getColumn(2).setPreferredWidth(90); tcm.getColumn(3).setPreferredWidth(40); tcm.getColumn(4).setPreferredWidth(90);

s_pan = new JScrollPane(table); 入滚动框

//将表格加

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){ return true; }

if(obj instanceof String) { String str = (String)obj; return str.equals(id); }

return false;

}

public void actionPerformed(ActionEvent e){ if(e.getSource()==search){ removeData();

try{ Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select

Course.Course_ID,Course_Name,Tea_Names,Course_Count from Course,Teacher_Info,TC where Course.Course_ID=TC.Course_ID and Teacher_Info.Tea_ID=TC.Tea_ID\");

while(rs.next()){ addData(rs.getString(1),rs.getString(2),rs.getString(3)); }

}catch(Exception ex){ }

ex.getStackTrace();

}

if(e.getSource()==reset){ removeData(); }

if(e.getSource()==submit){

try{

String teacher=\"\"; String teacherid=\"\"; String courseid=\"\"; int temp=0;

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement();

int flag=0;

int col = model.getColumnCount();

int row = model.getRowCount(); for (int i = 0; i < row; i++){ if(model.getValueAt(i, 4).toString()==\"true\"){ teacher=(String)model.getValueAt(i, 3);

ResultSet rs=stat.executeQuery(\"select Tea_ID from Teacher_Info where Tea_Names='\"+teacher+\"'\");

while(rs.next()){ teacherid=rs.getString(1); }

courseid=(String)model.getValueAt(i, 1);

ResultSet rss=stat.executeQuery(\"select Stu_ID,Course_ID while(rss.next()){ if(rss.getString(1).equals(id) && }

flag=1;

from SC\");

rss.getString(2).equals(courseid))

if(flag!=1)

temp+=stat.executeUpdate(\"insert into

SC(Stu_ID,Course_ID,Tea_ID) values('\"+id+\"','\"+courseid+\"','\"+teacherid+\"')\");

}

} if(temp>0){ JOptionPane.showMessageDialog(ss,\"选课成功\");

}

}

else if(temp<=0 && flag==1)

JOptionPane.showMessageDialog(ss,\"课程已选,选课失败\"); else

JOptionPane.showMessageDialog(ss,\"选课失败\");

}catch(Exception ex){

ex.getStackTrace();

} }

private void addData(String id,String name,String teacher) { model.addRow(id,name,teacher,false); table.updateUI(); }

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }

// public static void main(String args[]) // {

// new student_course(\"1\"); // } }

18.学生修改信息 package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class student_info extends JFrame implements ActionListener{

static student_info ss;

String userID=\"\"; String sex=\"\"; String age=\"\"; String cla=\"\"; String name=\"\";

//用户名 //性别 //年龄 //班级

//姓名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel jlid=new JLabel(\"学 号:\"); //创建文本框对象 JLabel jlname=new JLabel(\"姓 名:\"); JLabel jlsex=new JLabel(\"性 别:\"); JLabel jlage=new JLabel(\"年 龄:\"); JLabel jlcla=new JLabel(\"班 级:\");

JTextField jtid=new JTextField(); JTextField jtname=new JTextField(); JTextField jtsex=new JTextField(); JTextField jtage=new JTextField(); JTextField jtcla=new JTextField();

JButton submit=new JButton(\"添加\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public student_info(String id){ this.setTitle(\"添加学生基本信息\"); this.setLayout(null); this.add(jlid);

this.add(title); this.add(jlname); this.add(jlsex); this.add(jlage); this.add(jlcla);

this.add(jtid); this.add(jtname); this.add(jtsex); this.add(jtage); this.add(jtcla); jtid.setText(id);

jtid.setEditable(false); this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

//设置窗口标题

//设置窗口布局管理器 //将控件添加 到窗体

title.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"添加学生基本信息\"); title.setBounds(222,20,150,20); jlid.setBounds(180,60,100,20);

jlname.setBounds(180,100,100,20); jlsex.setBounds(180,140,100,20); jlage.setBounds(180,180,100,20); jlcla.setBounds(180,220,100,20);

jtid.setBounds(250,60,140,20);

jtname.setBounds(250,100,140,20); jtsex.setBounds(250,140,140,20); jtage.setBounds(250,180,140,20); jtcla.setBounds(250,220,140,20);

submit.setBounds(200,270,60,20);

}

reset.setBounds(300,270,60,20);

warning.setBounds(420,100,150,20);

submit.addActionListener(this); reset.addActionListener(this);

this.setSize(600,400); centerShell(this); this.setVisible(true);

this.setResizable(false); //设置窗体不可变大小 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){ }

return true;

if(obj instanceof String) { String str = (String)obj; return str.equals(userID); }

return false; }

public void actionPerformed(ActionEvent e){ userID=jtid.getText(); //获取用户输入内容

name=jtname.getText(); sex=jtsex.getText(); age=jtage.getText(); cla=jtcla.getText(); int temp=0; Connection con=null; if(e.getSource()==submit){

try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

temp=stat.executeUpdate(\"update Student_Info set

符串

Stu_Name='\"+name+\"',Stu_sex='\"+sex+\"',Stu_Age='\"+age+\"',Class_ID='\"+cla+\"' where Stu_ID='\"+userID+\"'\"); if(temp==1){ JOptionPane.showMessageDialog(ss,\"添加成功\");

}

}

else{ JOptionPane.showMessageDialog(ss,\"添加失败\"); }

ex.getStackTrace();

}catch(Exception ex){

}else if(e.getSource()==reset){ //重置所有控件

warning.setText(\"\"); }

jtname.setText(\"\"); jtsex.setText(\"\"); jtage.setText(\"\"); jtcla.setText(\"\");

}

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); } // // //

public static void main(String args[]){ new student_info(\"1\"); }

}

19.学生修改密码 package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*; import java.awt.event.*;

public class student_pwd extends JFrame implements ActionListener{

static student_pwd ss;

String userID=\"\"; //用户名 String pwd1=\"\"; String pwd2=\"\";

//密码

//确认密码

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note2=new JLabel(\"*\"); JLabel note3=new JLabel(\"*\");

JLabel jlID=new JLabel(\"学 号:\"); //使用文本框创建标签对象

JLabel jlPwd=new JLabel(\"密 码:\");

JLabel jlPwd2=new JLabel(\"确认密码:\");

JTextField jtID=new JTextField(); //创建文本框对象 JPasswordField jtPwd=new JPasswordField (); JPasswordField jtPwd2=new JPasswordField ();

JButton submit=new JButton(\"修改\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public student_pwd(String id){ //添加教师账号信息

this.setTitle(\"修改账号密码\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器 this.add(jlID); //将控件添加 到窗体 this.add(title); this.add(jlPwd); this.add(jlPwd2);

jtID.setEditable(false);

this.add(jtID); this.add(jtPwd); this.add(jtPwd2);

this.add(note2); this.add(note3);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

title.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

note3.setFont(new Font(\"red\ //设置提示字体 note3.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"修 改 学 生 密 码\"); //设置控件及窗体位置大小

title.setBounds(240,30,150,20);

jlID.setBounds(180,90,100,20); jlPwd.setBounds(180,140,100,20); jlPwd2.setBounds(180,190,100,20); jtID.setText(id);

jtID.setBounds(250,90,140,20); jtPwd.setBounds(250,140,140,20); jtPwd2.setBounds(250,190,140,20);

note2.setBounds(400,140,140,20); note3.setBounds(400,190,140,20);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,90,150,20); //设置提示框位置大小

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

}

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等

if(obj==null) return false;

if(this == obj){ return true; }

if(obj instanceof String) { String str = (String)obj; return str.equals(pwd1); }

return false; }

public void actionPerformed(ActionEvent e){ //获取用户输入内容

userID=jtID.getText(); pwd1=jtPwd.getText(); pwd2=jtPwd2.getText();

int temp=0,flag=0; Connection con=null;

if(e.getSource()==submit){

//判断是否已输入必填信息

if(pwd1.equals(\"\") || pwd2.equals(\"\")){ warning.setText(\"请输入必填信息\");

}

else if(!pwd1.equals(pwd2)){ //判断两次输入密码是 }

warning.setText(\"两次输入密码不相同\");

否一致

else{ try{

符串

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字

Statement stat=con.createStatement();

temp=stat.executeUpdate(\"update Student_Info set Stu_Pwd='\"+pwd1+\"' where Stu_ID='\"+userID+\"'\");

if(temp==1){ JOptionPane.showMessageDialog(ss,\"修改密码成功\"); } else{ }

JOptionPane.showMessageDialog(ss,\"修改密码失败\");

}catch(Exception ex){ }

ex.getStackTrace();

}

}else if(e.getSource()==reset){ warning.setText(\"\");

jtPwd.setText(\"\"); jtPwd2.setText(\"\");

} }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); } // //

public static void main(String[] args){ new student_pwd(\"1\");

// }

}

20.学生查询分数 package SIMS;

import java.awt.BorderLayout; import java.awt.Color; import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.lang.*;

public class student_score extends JFrame implements ActionListener{ String userid=\"\";

private JFrame frame = null; private JTable table = null;

private table_model_student_score model = null; private JScrollPane s_pan = null; //滚动块 private JButton submit = null, reset = null; private JPanel pane = null;

public student_score(String id) { userid=id;

frame = new JFrame(\"查询课程分数\"); pane = new JPanel();

submit = new JButton(\"查询数据\"); reset = new JButton(\"清除数据\");

pane.add(submit); pane.add(reset);

submit.addActionListener(this); reset.addActionListener(this);

model = new table_model_student_score(20);

table = new JTable(model){

//重写getCellRenderer

方法,设置表格中内容居中显示

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(40); tcm.getColumn(2).setPreferredWidth(90); tcm.getColumn(3).setPreferredWidth(40); tcm.getColumn(4).setPreferredWidth(90);

s_pan = new JScrollPane(table);

//将表格加

入滚动框

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==submit){ removeData(); try{ Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement(); ResultSet rs=stat.executeQuery(\"select

Course.Course_ID,Course_Name,Tea_Names,Score from Course,Teacher_Info,SC where Course.Course_ID=SC.Course_ID and Teacher_Info.Tea_ID=SC.Tea_ID and Stu_ID='\"+userid+\"'\");

while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)); }

}catch(Exception ex){ ex.getStackTrace(); }

}

if(e.getSource()==reset){ } }

removeData();

private void addData(String id,String name,String sex,String sdept) { model.addRow(id,name,sex,sdept); table.updateUI(); }

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大

if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }

// public static void main(String args[]) // { //

new student_score(\"1\"); // } }

21.教师界面

package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*; import java.awt.Toolkit;

public class teacher extends JFrame implements ActionListener{ String teacherid=\"\";

JTextArea theArea=null; //创建菜单栏 JMenuBar MBar=new JMenuBar(); JPanel panel=new JPanel(); JLabel hello=new JLabel();

JButton exit=new JButton(\"退 出 登 录\");

JMenu change=new JMenu(\"修改信息\"); JMenu score=new JMenu(\"分数管理\"); JMenu course=new JMenu(\"教授课程\");

JMenuItem cha_student=new JMenuItem(\"账号信息\"); //创建二级菜单 JMenuItem cha_password=new JMenuItem(\"密码信息\"); JMenuItem score2=new JMenuItem(\"录入分数\"); JMenuItem course2=new JMenuItem(\"授课查询\");

JMenuItem score3=new JMenuItem(\"查看分数\");

public teacher(String name,String ID){ teacherid=ID;

cha_student.addActionListener(this); cha_password.addActionListener(this); score2.addActionListener(this); course2.addActionListener(this); score3.addActionListener(this);

change.add(cha_student); //添加二级菜单内容 change.add(cha_password); score.add(score2); course.add(course2);

score.add(score3);

MBar.add(change); //将菜单添加至菜单栏 MBar.add(score); MBar.add(course);

setJMenuBar(MBar); //添加菜单

hello.setBounds(20,50,300,200); exit.setBounds(220,160,140,20);

panel.setBounds(10,100,550,320);

hello.setFont(new Font(\"\ //设置提示字体 hello.setForeground(Color.blue);

hello.setText(\"欢迎教师 \\\"\"+name+\"\\\" 登录\"); //显示登录者身份提示

panel.add(hello); this.add(exit);

this.add(panel);

exit.addActionListener(this); //添加退出按钮动作监听器

this.setTitle(\"教师界面\"); this.setLayout(null);

this.setResizable(false); //设置窗体大小不可变 this.setSize(600,400); //设置窗体大小

centerShell(this); //窗体在屏幕中间显示

this.setVisible(true); //设置窗体可见

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/* JTextArea theArea=new JTextArea(); //添加文本显示区域 theArea.setEditable(true);

getContentPane().setLayout(new BorderLayout());

getContentPane().add(new JScrollPane(theArea),BorderLayout.CENTER); */ }

public void actionPerformed(ActionEvent e){ //动作监听事件 }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

if(e.getSource()==exit){

this.dispose(); new login();

}else if(e.getSource()==cha_password){ new teacher_pwd(teacherid); }else if(e.getSource()==cha_student){ new teacher_info(teacherid); }else if(e.getSource()==score2){ new teacher_addscore(teacherid); }else if(e.getSource()==course2){ new teacher_course(teacherid); }else if(e.getSource()==score3){ new teacher_search(); }

// // // }

public static void main(String[] args){ new teacher(\"QQ\ }

22.教师录入成绩 package SIMS;

import java.awt.BorderLayout; import java.awt.Color;

import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.lang.*;

public class teacher_addscore extends JFrame implements ActionListener{ static teacher_addscore ss;

String id=\"\";

private JFrame frame = null; private JTable table = null;

private table_model_teacher_addscore model = null;

private JScrollPane s_pan = null; //滚动块 private JButton submit = null, reset = null; private JButton search=null; private JPanel pane = null;

public teacher_addscore(String teacherid) { id=teacherid;

frame = new JFrame(\"录入学生成绩\"); pane = new JPanel();

search = new JButton(\"查询课程\"); reset = new JButton(\"清除数据\");

submit = new JButton(\"确认提交\");

pane.add(search); pane.add(reset);

pane.add(submit);

search.addActionListener(this); reset.addActionListener(this); submit.addActionListener(this);

model = new table_model_teacher_addscore(20);

table = new JTable(model){

//重写getCellRenderer

方法,设置表格中内容居中显示

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(40); tcm.getColumn(2).setPreferredWidth(90); tcm.getColumn(3).setPreferredWidth(70); tcm.getColumn(4).setPreferredWidth(60);

s_pan = new JScrollPane(table); 入滚动框

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==search){

removeData(); try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select distinct

//将表格加

SC.Stu_ID,Stu_Name,Course_Name,Score from SC,Student_Info,Course,TC where Student_Info.Stu_ID=SC.Stu_ID and Course.Course_ID=SC.Course_ID and TC.Tea_ID=SC.Tea_ID and TC.Tea_ID='\"+id+\"'\"); while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4));

}

}catch(Exception ex){ ex.getStackTrace(); }

}

if(e.getSource()==reset){ }

removeData();

if(e.getSource()==submit){

try{ int temp=0;

String studentid=\"\"; String courseid=\"\"; String coursename=\"\"; String score=\"\";

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement();

int col = model.getColumnCount();

int row = model.getRowCount(); for (int i = 0; i < row; i++){

studentid=(String)model.getValueAt(i, 1); coursename=(String)model.getValueAt(i, 3);

ResultSet rs=stat.executeQuery(\"select Course_ID from Course while(rs.next()){ }

courseid=rs.getString(1);

where Course_Name='\"+coursename+\"'\");

score=(String)model.getValueAt(i, 4);

temp+=stat.executeUpdate(\"update SC set score='\"+score+\"' where Stu_ID='\"+studentid+\"' and Course_ID='\"+courseid+\"' and Tea_ID='\"+id+\"'\");

}

if(temp>0){ JOptionPane.showMessageDialog(ss,\"打分成功\"); } else

JOptionPane.showMessageDialog(ss,\"打分失败\"); }catch(Exception ex){ }

ex.getStackTrace();

} }

private void addData(String id,String studentname,String coursename,String score) {

model.addRow(id,studentname,coursename,score); table.updateUI(); }

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI();

}

private void centerShell(JFrame shell) //窗口在屏幕中间显示

{

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }

// public static void main(String args[]) // {

// new teacher_addscore(\"1\"); // } }

23.教师查询授课 package SIMS;

import java.awt.BorderLayout; import java.awt.Color; import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.lang.*;

public class teacher_addscore extends JFrame implements ActionListener{ static teacher_addscore ss;

String id=\"\";

private JFrame frame = null; private JTable table = null;

private table_model_teacher_addscore model = null; private JScrollPane s_pan = null; //滚动块 private JButton submit = null, reset = null; private JButton search=null; private JPanel pane = null;

public teacher_addscore(String teacherid) { id=teacherid;

frame = new JFrame(\"录入学生成绩\"); pane = new JPanel();

search = new JButton(\"查询课程\"); reset = new JButton(\"清除数据\");

submit = new JButton(\"确认提交\");

pane.add(search); pane.add(reset); pane.add(submit);

search.addActionListener(this); reset.addActionListener(this); submit.addActionListener(this);

model = new table_model_teacher_addscore(20);

table = new JTable(model){ //重写getCellRenderer方法,设置表格中内容居中显示

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(40); tcm.getColumn(2).setPreferredWidth(90); tcm.getColumn(3).setPreferredWidth(70); tcm.getColumn(4).setPreferredWidth(60);

s_pan = new JScrollPane(table); 入滚动框

//将表格加

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==search){

removeData(); try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement(); ResultSet rs=stat.executeQuery(\"select distinct

SC.Stu_ID,Stu_Name,Course_Name,Score from SC,Student_Info,Course,TC where Student_Info.Stu_ID=SC.Stu_ID and Course.Course_ID=SC.Course_ID and TC.Tea_ID=SC.Tea_ID and TC.Tea_ID='\"+id+\"'\"); while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4)); }

}catch(Exception ex){ }

ex.getStackTrace();

}

if(e.getSource()==reset){ removeData(); }

if(e.getSource()==submit){

try{

int temp=0; String studentid=\"\"; String courseid=\"\"; String coursename=\"\"; String score=\"\";

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement();

int col = model.getColumnCount();

int row = model.getRowCount(); for (int i = 0; i < row; i++){ studentid=(String)model.getValueAt(i, 1); coursename=(String)model.getValueAt(i, 3);

ResultSet rs=stat.executeQuery(\"select Course_ID from Course where Course_Name='\"+coursename+\"'\");

while(rs.next()){ courseid=rs.getString(1); }

score=(String)model.getValueAt(i, 4);

temp+=stat.executeUpdate(\"update SC set score='\"+score+\"' where Stu_ID='\"+studentid+\"' and Course_ID='\"+courseid+\"' and Tea_ID='\"+id+\"'\");

}

if(temp>0){ JOptionPane.showMessageDialog(ss,\"打分成功\"); } else

JOptionPane.showMessageDialog(ss,\"打分失败\"); }catch(Exception ex){ ex.getStackTrace();

}

} }

private void addData(String id,String studentname,String coursename,String score) {

model.addRow(id,studentname,coursename,score); table.updateUI(); }

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }

// public static void main(String args[]) // {

// new teacher_addscore(\"1\"); // } }

24.教师查询授课信息 package SIMS;

import java.awt.BorderLayout; import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel;

import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*;

import java.sql.*; import java.lang.*;

public class teacher_course extends JFrame implements ActionListener{ String id=\"\";

static teacher_course ss;

private JFrame frame = null; private JTable table = null;

private table_model_teacher_course model = null; private JScrollPane s_pan = null; //滚动块 private JButton submit = null, reset = null; private JButton search=null; private JPanel pane = null;

public teacher_course(String studentid) { id=studentid;

frame = new JFrame(\"教师授课信息\"); pane = new JPanel();

search = new JButton(\"查询课程\"); reset = new JButton(\"清除数据\");

pane.add(search);

pane.add(reset);

search.addActionListener(this);

reset.addActionListener(this);

model = new table_model_teacher_course(20);

table = new JTable(model){ 方法,设置表格中内容居中显示

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(30); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(30); tcm.getColumn(2).setPreferredWidth(110); tcm.getColumn(3).setPreferredWidth(60);

s_pan = new JScrollPane(table); 入滚动框

//将表格加

//重写getCellRenderer

frame.getContentPane().add(s_pan, BorderLayout.CENTER); frame.getContentPane().add(pane, BorderLayout.NORTH); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==search){

removeData(); try{ Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字符串 Statement stat=con.createStatement(); ResultSet rs=stat.executeQuery(\"select

Course.Course_ID,Course_Name,Course_Count from Course,TC where Course.Course_ID=TC.Course_ID and TC.Tea_ID='\"+id+\"'\"); while(rs.next()){

}

}

addData(rs.getString(1),rs.getString(2),rs.getString(3));

}catch(Exception ex){

ex.getStackTrace();

}

if(e.getSource()==reset){ removeData(); } }

private void addData(String id,String name,String count) { model.addRow(id,name,count); table.updateUI(); }

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI();

}

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth)

shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight -

shellHeight) / 2) );

}

// public static void main(String args[]) // {

// new teacher_course(\"1\"); // } }

25.教师修改信息 package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*;

import java.awt.event.*;

public class teacher_info extends JFrame implements ActionListener{

static teacher_info ss;

String userID=\"\"; String sex=\"\"; String age=\"\"; String cla=\"\";

//用户名 //性别

//年龄 //班级

String name=\"\"; //姓名

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel jlid=new JLabel(\"教 工 号:\"); //创建文本框对象 JLabel jlname=new JLabel(\"姓 名:\"); JLabel jlsex=new JLabel(\"性 别:\"); JLabel jlage=new JLabel(\"年 龄:\"); JLabel jlcla=new JLabel(\"班 级:\");

JTextField jtid=new JTextField(); JTextField jtname=new JTextField(); JTextField jtsex=new JTextField(); JTextField jtage=new JTextField(); JTextField jtcla=new JTextField();

JButton submit=new JButton(\"添加\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public teacher_info(String id){ this.setTitle(\"添加教师基本信息\");

this.setLayout(null); this.add(jlid); this.add(title); this.add(jlname); this.add(jlsex); this.add(jlage); this.add(jlcla);

this.add(jtid); this.add(jtname); this.add(jtsex); this.add(jtage); this.add(jtcla); jtid.setText(id); jtid.setEditable(false); this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

//设置窗口标题 //设置窗口布局管理器 //将控件添加 到窗体

title.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"添加教师基本信息\"); title.setBounds(222,20,150,20); jlid.setBounds(180,60,100,20);

jlname.setBounds(180,100,100,20); jlsex.setBounds(180,140,100,20); jlage.setBounds(180,180,100,20); jlcla.setBounds(180,220,100,20);

jtid.setBounds(250,60,140,20);

jtname.setBounds(250,100,140,20); jtsex.setBounds(250,140,140,20); jtage.setBounds(250,180,140,20); jtcla.setBounds(250,220,140,20);

}

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,100,150,20);

submit.addActionListener(this); reset.addActionListener(this);

this.setSize(600,400); centerShell(this);

this.setVisible(true);

this.setResizable(false); //设置窗体不可变大小 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等 if(obj==null) return false; if(this == obj){

return true; }

if(obj instanceof String) { String str = (String)obj; return str.equals(userID); }

return false; }

public void actionPerformed(ActionEvent e){ userID=jtid.getText(); //获取用户输入内容

name=jtname.getText(); sex=jtsex.getText(); age=jtage.getText(); cla=jtcla.getText(); int temp=0;

Connection con=null;

if(e.getSource()==submit){

try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

符串

temp=stat.executeUpdate(\"update Teacher_Info set

Tea_Names='\"+name+\"',Tea_sex='\"+sex+\"',Tea_Age='\"+age+\"',Class_ID='\"+cla+\"' where Tea_ID='\"+userID+\"'\"); }

if(temp==1){ JOptionPane.showMessageDialog(ss,\"添加成功\"); } else{ }

JOptionPane.showMessageDialog(ss,\"添加失败\");

}catch(Exception ex){ }

ex.getStackTrace();

}else if(e.getSource()==reset){ //重置所有控件 warning.setText(\"\"); jtname.setText(\"\"); }

jtsex.setText(\"\"); jtage.setText(\"\"); jtcla.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight) shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); } //

public static void main(String args[]){

// // }

}

new teacher_info(\"1\");

26.教师修改密码 package SIMS;

import javax.swing.*;

import java.sql.*; import java.awt.*; import java.awt.event.*;

public class teacher_pwd extends JFrame implements ActionListener{

static teacher_pwd ss;

String userID=\"\"; //用户名 String pwd1=\"\"; String pwd2=\"\";

//密码

//确认密码

JLabel warning=new JLabel(); //输入信息提示框 JLabel title=new JLabel();

JLabel note2=new JLabel(\"*\"); JLabel note3=new JLabel(\"*\");

JLabel jlID=new JLabel(\"教 工 号:\"); //使用文本框创建标签对象 JLabel jlPwd=new JLabel(\"密 码:\"); JLabel jlPwd2=new JLabel(\"确认密码:\");

JTextField jtID=new JTextField(); //创建文本框对象 JPasswordField jtPwd=new JPasswordField (); JPasswordField jtPwd2=new JPasswordField ();

JButton submit=new JButton(\"修改\"); //创建按钮对象 JButton reset=new JButton(\"重置\");

public teacher_pwd(String id){ //添加教师账号信息

this.setTitle(\"修改账号密码\"); //设置窗口标题

this.setLayout(null); //设置窗口布局管理器 this.add(jlID); //将控件添加 到窗体 this.add(title); this.add(jlPwd);

this.add(jlPwd2); jtID.setEditable(false);

this.add(jtID); this.add(jtPwd); this.add(jtPwd2);

this.add(note2); this.add(note3);

this.add(submit); this.add(reset);

this.add(warning);

title.setFont(new Font(\"red\ //设置提示字体

title.setForeground(Color.red);

note2.setFont(new Font(\"red\ //设置提示字体 note2.setForeground(Color.red);

note3.setFont(new Font(\"red\ //设置提示字体 note3.setForeground(Color.red);

warning.setFont(new Font(\"red\ //设置提示字体 warning.setForeground(Color.red);

title.setText(\"修 改 教 师 密 码\"); //设置控件及窗体位置大小

title.setBounds(240,30,150,20);

jlID.setBounds(180,90,100,20); jlPwd.setBounds(180,140,100,20); jlPwd2.setBounds(180,190,100,20); jtID.setText(id);

jtID.setBounds(250,90,140,20); jtPwd.setBounds(250,140,140,20); jtPwd2.setBounds(250,190,140,20);

note2.setBounds(400,140,140,20); note3.setBounds(400,190,140,20);

submit.setBounds(200,270,60,20); reset.setBounds(300,270,60,20);

warning.setBounds(420,90,150,20); //设置提示框位置大小

}

submit.addActionListener(this); //添加监听器 reset.addActionListener(this);

this.setSize(600,400); //设置窗体大小

centerShell(this); //设置窗口位置在屏幕中央 this.setResizable(false); //设置窗体不可变大小 this.setVisible(true); //设置窗口可见性 this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

public boolean equals(Object obj){ //重写equals方法判断字符串相等

if(obj==null) return false;

if(this == obj){ return true; }

if(obj instanceof String) { String str = (String)obj; return str.equals(pwd1); }

return false; }

public void actionPerformed(ActionEvent e){ //获取用户输入内容

userID=jtID.getText(); pwd1=jtPwd.getText(); pwd2=jtPwd2.getText();

int temp=0,flag=0;

//判断是否已输入必填信息

Connection con=null;

if(e.getSource()==submit){

if(pwd1.equals(\"\") || pwd2.equals(\"\")){ warning.setText(\"请输入必填信息\"); }

else if(!pwd1.equals(pwd2)){ //判断两次输入密码是 }

warning.setText(\"两次输入密码不相同\");

否一致

else{ try{ String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

temp=stat.executeUpdate(\"update Teacher_Info set

符串

Tea_Pwd='\"+pwd1+\"' where Tea_ID='\"+userID+\"'\"); }

}

if(temp==1){ JOptionPane.showMessageDialog(ss,\"修改密码成功\"); } else{ }

JOptionPane.showMessageDialog(ss,\"修改密码失败\");

}catch(Exception ex){ }

ex.getStackTrace();

}else if(e.getSource()==reset){ warning.setText(\"\"); }

jtPwd.setText(\"\"); jtPwd2.setText(\"\");

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度 int shellHeight = shell.getBounds().height; int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight;

if(shellWidth > screenWidth) shellWidth = screenWidth;

//让窗口在屏幕中间显示

shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2)); }

// // // }

public static void main(String[] args){ }

new student_pwd(\"1\");

27.教师查询成绩 package SIMS;

import java.awt.BorderLayout; import java.awt.Color;

import java.awt.Toolkit;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector; import java.awt.*;

import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.*; import javax.swing.*; import java.sql.*; import java.lang.*;

public class teacher_search extends JFrame implements ActionListener{

private JFrame frame = null;

private JTable table = null;

private table_model_teacher_teacher model = null;

private JScrollPane s_pan = null; //滚动块

private JButton submit = new JButton(\"查询\"),clear= new JButton(\"清除\"),reset=new JButton(\"重置\");; private JPanel pane = null; JLabel ID=new JLabel(\"ID :\");

JTextField jtid=new JTextField();

JRadioButton jb1=new JRadioButton(\"全部\"); JRadioButton jb2=new JRadioButton(\"按班级\"); JRadioButton jb3=new JRadioButton(\"按院系\"); ButtonGroup bg=new ButtonGroup();

public teacher_search() {

model = new table_model_teacher_teacher(20);

table = new JTable(model){ 方法,设置表格中内容居中显示

public TableCellRenderer getCellRenderer(int row, int column) {

TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof JLabel) {

((JLabel) renderer).setHorizontalAlignment(JLabel.CENTER); }

return renderer; } };

jb1.setSelected(true);

table.setBackground(Color.white);

TableColumnModel tcm = table.getColumnModel();

tcm.getColumn(0).setPreferredWidth(40); //设置表格每列的宽度

tcm.getColumn(1).setPreferredWidth(60); tcm.getColumn(2).setPreferredWidth(90); tcm.getColumn(3).setPreferredWidth(60); tcm.getColumn(4).setPreferredWidth(50);

frame = new JFrame(\"查询成绩信息\"); frame.setLayout(null);

table.setBounds(0,0,500,300); s_pan = new JScrollPane(table); 入滚动框 frame.add(s_pan); pane = new JPanel(); frame.add(pane); frame.add(s_pan);

bg.add(jb1); bg.add(jb2); bg.add(jb3);

//将表格加

//重写getCellRenderer

frame.add(ID); frame.add(jtid); frame.add(jb2); frame.add(jb3); frame.add(jb1);

s_pan.setBounds(0,50,600,300); ID.setBounds(10,15,20,20); jtid.setBounds(40,15,80,20); jb1.setBounds(135,16,58,20); jb2.setBounds(190,16,70,20); jb3.setBounds(260,15,70,20);

pane.setLayout(null); pane.add(submit); pane.add(reset); pane.add(clear);

submit.setBounds(0,5,60,22);

reset.setBounds(70,5,60,22); clear.setBounds(140,5,60,22); pane.setBounds(350,8,400,30);

submit.addActionListener(this); reset.addActionListener(this); clear.addActionListener(this);

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(600, 400);

centerShell(frame); //设置窗体居中显示 frame.setResizable(false); frame.setVisible(true); }

public void actionPerformed(ActionEvent e){ if(e.getSource()==submit){

removeData(); if(jb1.isSelected()){

try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

ResultSet rs=stat.executeQuery(\"select distinct

符串

Stu_Name,Course_Name,Tea_Names,Student_Info.Class_ID,Student_Info.Depart,Score from Student_Info,SC,Teacher_Info,Course where Student_Info.Stu_ID=SC.Stu_ID and Teacher_Info.Tea_ID=SC.Tea_ID and Course.Course_ID=SC.Course_ID\");

while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6));

}

}

}catch(Exception ex){ }

ex.getStackTrace();

if(jb2.isSelected()){

try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

符串

ResultSet rs=stat.executeQuery(\"select distinct

Stu_Name,Course_Name,Tea_Names,Student_Info.Class_ID,Student_Info.Depart,Score from Student_Info,SC,Teacher_Info,Course where Student_Info.Stu_ID=SC.Stu_ID and Teacher_Info.Tea_ID=SC.Tea_ID and Course.Course_ID=SC.Course_ID and Student_Info.Class_ID='\"+jtid.getText()+\"'\");

while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6));

}

}

}catch(Exception ex){ ex.getStackTrace(); }

if(jb3.isSelected()){ try{

Connection con=null;

String url=\"jdbc:odbc:SIMS\"; //连接数据库

con=DriverManager.getConnection(url,\"\ //获取连接字Statement stat=con.createStatement();

符串

ResultSet rs=stat.executeQuery(\"select distinct

Stu_Name,Course_Name,Tea_Names,Student_Info.Class_ID,Student_Info.Depart,Score from Student_Info,SC,Teacher_Info,Course where Student_Info.Stu_ID=SC.Stu_ID and Teacher_Info.Tea_ID=SC.Tea_ID and Course.Course_ID=SC.Course_ID and Student_Info.Depart='\"+jtid.getText()+\"'\");

while(rs.next()){

addData(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6));

}

}

}catch(Exception ex){ }

ex.getStackTrace();

}

if(e.getSource()==clear){ removeData(); }

if(e.getSource()==reset){ jtid.setText(\"\"); } }

jb1.setSelected(true);

private void addData(String id,String name,String sex,String cla,String sdept,String score) {

model.addRow(id,name,sex,cla,sdept,score); table.updateUI(); }

private void removeData() {

model.removeRows(0, model.getRowCount()); table.updateUI(); }

private void centerShell(JFrame shell) //窗口在屏幕中间显示 {

//得到屏幕的宽度和高度

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; //得到Shell窗口的宽度和高度

int shellHeight = shell.getBounds().height;

int shellWidth = shell.getBounds().width;

//如果窗口大小超过屏幕大小,让窗口与屏幕等大 if(shellHeight > screenHeight)

shellHeight = screenHeight; if(shellWidth > screenWidth) shellWidth = screenWidth; //让窗口在屏幕中间显示

shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) ); }

// public static void main(String args[]) { // new teacher_search(); // } }

28.管理员查询信息表格模型 package SIMS;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

class table_model_admin extends AbstractTableModel {

private static final long serialVersionUID = -7495940408592595397L;

private Vector content = null;

private String[] title_name = { \"序号\账号ID\姓名\性别\院系\" };

public table_model_admin() { content = new Vector(); }

public table_model_admin(int count) { content = new Vector(count);

}

public void addRow(String id, String name, String sex, String sdept) { Vector v = new Vector(5);

v.add(0, new Integer(content.size()+1)); v.add(1, id); v.add(2, name); v.add(3, sex); v.add(4, sdept); content.add(v); }

public void removeRow(int row) { content.remove(row); }

public void removeRows(int row, int count) { for (int i = 0; i < count; i++) { if (content.size() > row) { content.remove(row); } } }

/**

* 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效

*/

public boolean isCellEditable(int rowIndex, int columnIndex) { // if (columnIndex == 0) { // return false; // } return false; }

/**

* 使修改的内容生效

*/

public void setValueAt(Object value, int row, int col) { ((Vector) content.get(row)).remove(col); ((Vector) content.get(row)).add(col, value); this.fireTableCellUpdated(row, col); }

public String getColumnName(int col) { return title_name[col]; }

public int getColumnCount() { return title_name.length; }

public int getRowCount() { return content.size(); }

public Object getValueAt(int row, int col) {

return ((Vector) content.get(row)).get(col); }

/**

* 返回数据类型 */

// public Class getColumnClass(int col) { // return getValueAt(0, col).getClass(); // } }

29.管理员查询课程表格模型 package SIMS;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

class table_model_course extends AbstractTableModel {

private static final long serialVersionUID = -7495940408592595397L;

private Vector content = null;

private String[] title_name = { \"序号\课程ID\课程名\任课教师\课时\" };

public table_model_course() { content = new Vector(); }

public table_model_course(int count) {

content = new Vector(count); }

public void addRow(String id, String name, String sex, String sdept) { Vector v = new Vector(5);

v.add(0, new Integer(content.size()+1)); v.add(1, id); v.add(2, name); v.add(3, sex); v.add(4, sdept); content.add(v); }

public void removeRow(int row) { content.remove(row);

}

public void removeRows(int row, int count) { for (int i = 0; i < count; i++) { if (content.size() > row) { content.remove(row); } } }

/**

* 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效 */

public boolean isCellEditable(int rowIndex, int columnIndex) { // if (columnIndex == 0) { // return false; // } return false; }

/**

* 使修改的内容生效

*/

public void setValueAt(Object value, int row, int col) { ((Vector) content.get(row)).remove(col); ((Vector) content.get(row)).add(col, value); this.fireTableCellUpdated(row, col);

}

public String getColumnName(int col) { return title_name[col]; }

public int getColumnCount() { return title_name.length; }

public int getRowCount() { return content.size(); }

public Object getValueAt(int row, int col) {

return ((Vector) content.get(row)).get(col); }

/**

* 返回数据类型 */

// public Class getColumnClass(int col) { // return getValueAt(0, col).getClass(); // } }

30.学生选课表格模型 package SIMS;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

class table_model_student_course extends AbstractTableModel {

private static final long serialVersionUID = -7495940408592595397L;

private Vector content = null;

private String[] title_name = { \"序号\课程ID\ \"课程名\授课教师\选修\" };

public table_model_student_course() {

content = new Vector();

}

public table_model_student_course(int count) { content = new Vector(count); }

public void addRow(String id, String coursename,String teachername,boolean flag) {

Vector v = new Vector(5);

v.add(0, new Integer(content.size())); v.add(1, id);

v.add(2, coursename); v.add(3, teachername); v.add(4,new Boolean(flag)); content.add(v);

}

public void removeRow(int row) { content.remove(row); }

public void removeRows(int row, int count) { for (int i = 0; i < count; i++) { if (content.size() > row) { content.remove(row); } } }

/**

* 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效 */

public boolean isCellEditable(int rowIndex, int columnIndex) { if (columnIndex == 4) { return true; }

return false; }

/**

* 使修改的内容生效 */

public void setValueAt(Object value, int row, int col) { ((Vector) content.get(row)).remove(col); ((Vector) content.get(row)).add(col, value); this.fireTableCellUpdated(row, col); }

public String getColumnName(int col) { return title_name[col]; }

public int getColumnCount() { return title_name.length; }

public int getRowCount() { return content.size();

}

public Object getValueAt(int row, int col) { return ((Vector) content.get(row)).get(col); }

/**

* 返回数据类型 */

public Class getColumnClass(int col) { return getValueAt(0, col).getClass(); } }

31.学生查询分数表格模型

package SIMS;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

class table_model_student_score extends AbstractTableModel {

private static final long serialVersionUID = -7495940408592595397L;

private Vector content = null;

private String[] title_name = { \"序号\课程ID\课程名\任课教师\成绩\" };

public table_model_student_score(){ content = new Vector(); }

public table_model_student_score(int count) { content = new Vector(count); }

public void addRow(String id, String name, String sex, String sdept) { Vector v = new Vector(5);

v.add(0, new Integer(content.size()+1)); v.add(1, id); v.add(2, name); v.add(3, sex); v.add(4, sdept); content.add(v); }

public void removeRow(int row) { content.remove(row);

}

public void removeRows(int row, int count) { for (int i = 0; i < count; i++) { if (content.size() > row) { content.remove(row); } } }

/**

* 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效

*/

public boolean isCellEditable(int rowIndex, int columnIndex) { // if (columnIndex == 0) { // return false; // } return false; }

/**

* 使修改的内容生效

*/

public void setValueAt(Object value, int row, int col) { ((Vector) content.get(row)).remove(col); ((Vector) content.get(row)).add(col, value); this.fireTableCellUpdated(row, col); }

public String getColumnName(int col) { return title_name[col]; }

public int getColumnCount() { return title_name.length; }

public int getRowCount() { return content.size(); }

public Object getValueAt(int row, int col) {

return ((Vector) content.get(row)).get(col); }

/**

* 返回数据类型

*/

// public Class getColumnClass(int col) { // return getValueAt(0, col).getClass(); // } }

32.教师录入成绩表格模型

package SIMS;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

class table_model_teacher_addscore extends AbstractTableModel {

private static final long serialVersionUID = -7495940408592595397L;

private Vector content = null;

private String[] title_name = { \"序号\学生ID\ \"学生名\课程名\分数\" };

public table_model_teacher_addscore() { content = new Vector(); }

public table_model_teacher_addscore(int count) { content = new Vector(count); }

public void addRow(String id, String studentname,String coursename,String score) { Vector v = new Vector(5);

v.add(0, new Integer(content.size())); v.add(1, id);

v.add(2, studentname); v.add(3, coursename); v.add(4, score); content.add(v); }

public void removeRow(int row) { content.remove(row); }

public void removeRows(int row, int count) { for (int i = 0; i < count; i++) { if (content.size() > row) { content.remove(row); } } }

/**

* 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效

*/

public boolean isCellEditable(int rowIndex, int columnIndex) { if (columnIndex == 4) { return true; }

return false; }

/**

* 使修改的内容生效 */

public void setValueAt(Object value, int row, int col) { ((Vector) content.get(row)).remove(col); ((Vector) content.get(row)).add(col, value); this.fireTableCellUpdated(row, col); }

public String getColumnName(int col) { return title_name[col]; }

public int getColumnCount() { return title_name.length; }

public int getRowCount() { return content.size(); }

public Object getValueAt(int row, int col) {

return ((Vector) content.get(row)).get(col); }

/**

* 返回数据类型 */ }

33.教师授课信息 表格模型 package SIMS;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

class table_model_teacher_course extends AbstractTableModel {

private static final long serialVersionUID = -7495940408592595397L;

private Vector content = null;

private String[] title_name = { \"序号\课程ID\课程名\课时\" };

public table_model_teacher_course() { content = new Vector(); }

public table_model_teacher_course(int count) { content = new Vector(count); }

public void addRow(String id, String coursename,String coursecount) { Vector v = new Vector(4);

v.add(0, new Integer(content.size())); v.add(1, id);

v.add(2, coursename); v.add(3, coursecount); content.add(v); }

public void removeRow(int row) {

content.remove(row); }

public void removeRows(int row, int count) { for (int i = 0; i < count; i++) { if (content.size() > row) { content.remove(row); } } }

/**

* 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效 */

public boolean isCellEditable(int rowIndex, int columnIndex) { if (columnIndex == 4) { return true; }

return false; }

/**

* 使修改的内容生效

*/

public void setValueAt(Object value, int row, int col) { ((Vector) content.get(row)).remove(col); ((Vector) content.get(row)).add(col, value); this.fireTableCellUpdated(row, col); }

public String getColumnName(int col) { return title_name[col]; }

public int getColumnCount() { return title_name.length; }

public int getRowCount() { return content.size(); }

public Object getValueAt(int row, int col) { return ((Vector) content.get(row)).get(col); }

/**

* 返回数据类型 */ }

34.教师查询成绩表格模型

package SIMS;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

class table_model_teacher_teacher extends AbstractTableModel {

private static final long serialVersionUID = -7495940408592595397L;

private Vector content = null;

private String[] title_name = { \"序号\学生姓名\ \"课程名\教师姓名\班级\院系\分数\" };

public table_model_teacher_teacher() { content = new Vector(); }

public table_model_teacher_teacher(int count) { content = new Vector(count); }

public void addRow(String studentname, String coursename,String teachername,String cla,String sdept,String score) { Vector v = new Vector(7);

v.add(0, new Integer(content.size())); v.add(1, studentname); v.add(2, coursename); v.add(3, teachername); v.add(4, cla); v.add(5, sdept); v.add(6, score); content.add(v); }

public void removeRow(int row) { content.remove(row); }

public void removeRows(int row, int count) { for (int i = 0; i < count; i++) { if (content.size() > row) { content.remove(row); } } }

/**

* 让表格中某些值可修改,但需要setValueAt(Object value, int row, int col)方法配合才能使修改生效

*/

public boolean isCellEditable(int rowIndex, int columnIndex) { // if (columnIndex == 4) { // return true; // }

return false; }

/**

* 使修改的内容生效 */

public void setValueAt(Object value, int row, int col) { ((Vector) content.get(row)).remove(col); ((Vector) content.get(row)).add(col, value); this.fireTableCellUpdated(row, col); }

public String getColumnName(int col) { return title_name[col]; }

public int getColumnCount() { return title_name.length; }

public int getRowCount() { return content.size(); }

public Object getValueAt(int row, int col) {

return ((Vector) content.get(row)).get(col); }

/**

* 返回数据类型 */ }

因篇幅问题不能全部显示,请点此查看更多更全内容