学生选课系统(数据库课程设计)

更新时间:2023-04-23 08:46:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

JAVA ,SQL server 数据库课程设计 学生选课系统

import java.sql.*;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.awt.event.*;
public class DLA extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
Choice c;
JLabel l1,l2,l3,l;
JTextField t1,t2;
JButton b1,b2;
public DLA(String str){
super(str);
p=new JPanel();
i=new ImageIcon("psue[9].jpg");
l=new JLabel(i);
l.setBounds(0,0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,30));
c=new Choice();
c.add(" 管 理 员 ");
c.add(" 教 师 ");
c.add(" 学 生 ");
l1=new JLabel("登陆身份");
l2=new JLabel("用户账号");
l3=new JLabel("用户密码");
t1=new JTextField("",10);
t2=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("退出");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(c);
p.add(l2);
p.add(t1);
p.add(l3);
p.add(t2);
p.add(b1);
p.add(b2);

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

if((t1.getText().equals("")||t2.getText().equals(""))||
((!c.getSelectedItem().equals(" 管 理 员 ")||!t1.getText().equals("SQS")||!t2.getText().equals("200628"))&&
(!c.getSelectedItem().equals(" 教 师 ")||!t1.getText().equals("JS")||!t2.getText().equals("123456"))&&
(!c.getSelectedItem().equals(" 学 生 ")||!t1.getText().equals("XS")||!t2.getText().equals("123456"))))
{ t1.setText("");t2.setText("");
JOptionPane.showMessageDialog(this,"账号或密码不能为空或错误!","提示",JOptionPane.WARNING_MESSAGE);}
if(c.getSelectedItem().equals(" 管 理 员 ")&&t1.getText().equals("SQS")&&t2.getText().equals("200628")){
this.dispose();
GLY gly=new GLY("管理员界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
if(c.getSelectedItem().equals(" 教 师 ")&&t1.getText().equals("JS")&&t2.getText().equals("123456")){
this.dispose();
JS js=new JS("教师界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
if(c.getSelectedItem().equals(" 学 生 ")&&t1.getText().equals("XS")&&t2.getText().equals("123456")){
this.dispose();
XS xs=new XS("学生界面");
xs.setLocati
on(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
}
if(e.getSource()==b2){
System.exit(0);
}
}
public static void main(String[

JAVA ,SQL server 数据库课程设计 学生选课系统

]args){
DLA dl=new DLA("登陆学生选课系统");
dl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
dl.setLocation(400, 200);
dl.setSize(500,300);
dl.setVisible(true);
}

}
class GLY extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l;
JButton b1,b2,b3,b4;
public GLY(String str){
super(str);
p=new JPanel();
i=new ImageIcon("http_imgload[5].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
b1=new JButton("管理教师");
b2=new JButton("管理学生");
b3=new JButton("管理课程");
b4=new JButton("返回上级");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
GLJS gly=new GLJS("管理教师界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
if(e.getSource()==b2){
this.dispose();
GLXS js=new GLXS("管理学生界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
if(e.getSource()==b3){
this.dispose();
GLKC xs=new GLKC("管理课程界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
if(e.getSource()==b4){
this.dispose();
DLA dl=new DLA("登陆学生选课系统");
dl.setLocation(400, 200);
dl.setSize(500,300);
dl.setVisible(true);
}
}
}
class JS extends JFrame implements ActionListener{
JPanel p;
JButton b1,b2,b3;
ImageIcon i;
JLabel l;
public JS(String str){
super(str);
p=new JPanel();
i=new ImageIcon("111115B19-1[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
b1=new JButton("个人代课界面");
b2=new JButton("查询自己信息");
b3=new JButton("返回上级");
p.add(b1);
p.add(b2);
p.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

}
public void actionPerfo
rmed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
JSDK gly=new JSDK("个人代课界面界面");
gly.setLocation(400, 200);
gly.setSize

JAVA ,SQL server 数据库课程设计 学生选课系统

(500,300);
gly.setVisible(true);
}
if(e.getSource()==b2){
this.dispose();
DLJSXX js=new DLJSXX("查询自己信息界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}

if(e.getSource()==b3){
this.dispose();
DLA dl=new DLA("登陆学生选课系统");
dl.setLocation(400, 200);
dl.setSize(500,300);
dl.setVisible(true);
}
}

}
class XS extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l;
JButton b1,b2,b3;
public XS(String str){
super(str);
p=new JPanel();
i=new ImageIcon("psbe[10].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
b1=new JButton("个人选课界面");
b2=new JButton("查询自己信息");
b3=new JButton("返回上级");
p.add(b1);
p.add(b2);
p.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
XSXK gly=new XSXK("个人选课界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
if(e.getSource()==b2){
this.dispose();
DLXSXX js=new DLXSXX("查询自己信息");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}

if(e.getSource()==b3){
this.dispose();
DLA dl=new DLA("登陆学生选课系统");
dl.setLocation(400, 200);
dl.setSize(500,300);
dl.setVisible(true);
}
}

}
class GLJS extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l;
JButton b1,b2,b3,b4;
public GLJS(String str){
super(str);
JPanel p=new JPanel();
i=new ImageIcon("qingchun09.jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
b1=new JButton("添加教师");
b2=new JButton("删除教师");
b3=new JButton("查询教师");
b4=new JButton("返回上级");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.a
ddActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
T

JAVA ,SQL server 数据库课程设计 学生选课系统

JJS gly=new TJJS("添加教师界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
if(e.getSource()==b2){
this.dispose();
SCJS js=new SCJS("删除教师界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
if(e.getSource()==b3){
this.dispose();
CXJS xs=new CXJS("查询教师界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
if(e.getSource()==b4){
this.dispose();
GLY gly=new GLY("管理员界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
}
}
class GLXS extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l;
JButton b1,b2,b3,b4;
public GLXS(String str){
super(str);
p=new JPanel();
i=new ImageIcon("截图1323070283.jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
b1=new JButton("添加学生");
b2=new JButton("删除学生");
b3=new JButton("查询学生");
b4=new JButton("返回上级");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
TJXS gly=new TJXS("添加学生界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
if(e.getSource()==b2){
this.dispose();
SCXS js=new SCXS("删除学生界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
if(e.getSource()==b3){
this.dispose();
CXXS xs=new CXXS("查询学生界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
if(e.getSource()==b4){
this.dispose();
GLY gly=new GLY("管理员界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
}
}
class GLKC extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l;
JButton b1,b2,b3,b4;
public GLKC(String str){
super(str);
p=new JPanel();
i=new ImageIcon("70b90e
f82ea9c0dc58ee905c[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(

JAVA ,SQL server 数据库课程设计 学生选课系统

Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
b1=new JButton("添加课程");
b2=new JButton("删除课程");
b3=new JButton("查询课程");
b4=new JButton("返回上级");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
TJKC gly=new TJKC("添加课程界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
if(e.getSource()==b2){
this.dispose();
SCKC js=new SCKC("删除课程界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
if(e.getSource()==b3){
this.dispose();
CXKC xs=new CXKC("查询课程界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
if(e.getSource()==b4){
this.dispose();
GLY gly=new GLY("管理员界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
}
}
class TJJS extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l2,l3,l4,l5,l;
JTextField t1,t2,t3,t4,t5;
JButton b1,b2;
public TJJS(String str){
super(str);
p=new JPanel();
i=new ImageIcon("4e7a010a4fa3f97be824885b[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,15));
l1=new JLabel("教职工号");
l2=new JLabel("教师姓名");
l3=new JLabel("教师性别");
l4=new JLabel("教师年龄");
l5=new JLabel("教师职称");
t1=new JTextField("",10);
t2=new JTextField("",10);
t3=new JTextField("",10);
t4=new JTextField("",10);
t5=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(l4);
p.add(t4);
p.add(l5);
p.add(t5);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")){
JOptionPane.showMessageDialog(this,"教职工号不能为空!","提示",
JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;

JAVA ,SQL server 数据库课程设计 学生选课系统

String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="INSERT INTO 教师表(教职工号,姓名,性别,年龄,职称) VALUES('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t1.setText("");t2.setText(""); t3.setText("");t4.setText(""); t5.setText("");
JOptionPane.showMessageDialog(this,"添加教师成功!","提示",RMATION_MESSAGE);}
}
if(e.getSource()==b2){
this.dispose();
GLJS gly=new GLJS("管理教师界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
}
}
class SCJS extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l;
JTextField t1;;
JButton b1,b2;
public SCJS(String str){
super(str);
p=new JPanel();
i=new ImageIcon("psue[21].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
l1=new JLabel("教职工号");
t1=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")){JOptionPane.showMessageDialog(this,"教职工号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="DELETE FROM 教师表 WHERE(教职工号='"+t1.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t1.setText("");
JOptionPane.showMessageDialog(this,"删除教师成功!","提示",RMATION_MESSAGE);}
}
if(e.getSource()==b2){

this.dispose();
GLJS gly=new GLJS("管理教师界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);
}
}

}
c

JAVA ,SQL server 数据库课程设计 学生选课系统

lass CXJS extends JFrame implements ActionListener{
JPanel p;
JButton b1;
MyTableModel11 mt;
JTable t;
JScrollPane s;
public CXJS(String str){
super(str);
setLayout(new BorderLayout());
mt=new MyTableModel11();
t=new JTable(mt);
s=new JScrollPane(t);
p=new JPanel();
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,10));
b1=new JButton("返回上级");
b1.addActionListener(this);
p.add(b1);
add(p,"South");
add(s,"Center");
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
GLJS js=new GLJS("管理教师界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}

}
class MyTableModel11 extends AbstractTableModel{

String jsnum,jsname,sex,age,work;
final String[] columnNames={"教职工号","姓名","性别","年龄","职称"};
Object[][]data=new Object[100][5];
public MyTableModel11(){
int m=0;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e){
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql=sql="SELECT * FROM 教师表";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
jsnum=rs.getString(1);
jsname=rs.getString(2);
sex=rs.getString(3);
age=rs.getString(4);
work=rs.getString(5);
data[m][0]=jsnum;data[m][1]=jsname;data[m][2]=sex;data[m][3]=age;data[m++][4]=work;
}
stmt.close();
con.close();
}catch(SQLException e){
}
}
public int getColumnCount(){
return columnNames.length;
}
public int getRowCount(){
return data.length;
}
public String getColumnName(int col){
return columnNames[col];
}
public Object getValueAt(int row,int col){
return data[row][col];
}
public void setValueAt(Object value,int row,int col){

System.out.println("New value of data:");
int numRows=getRowCount();
int numCols=getColumnCount();
for(int i=0;i<numRows;i++){
System.out.print("row"+i+":");
for(int j=0;j<numCols;j++){
System.out.print(" "+data[i][j]);
} System.out.println();
}System.out.println("----------------------");
}
}
class TJXS extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l2,l3,l4,l5,l;
JTextField t1,t2,t3,t4,t5;
JButton b1,b2;
public TJXS(String str){
super(str);
p=new JPanel();
i=new ImageIcon("http_imgload[8].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight()
);
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayou

JAVA ,SQL server 数据库课程设计 学生选课系统

t(FlowLayout.CENTER,110,15));
l1=new JLabel("学生学号");
l2=new JLabel("学生姓名");
l3=new JLabel("学生性别");
l4=new JLabel("学生年龄");
l5=new JLabel("学生专业");
t1=new JTextField("",10);
t2=new JTextField("",10);
t3=new JTextField("",10);
t4=new JTextField("",10);
t5=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(l4);
p.add(t4);
p.add(l5);
p.add(t5);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")){JOptionPane.showMessageDialog(this,"学生学号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="INSERT INTO 学生表(学号,姓名,性别,年龄,专业) VALUES('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"','"+t4.getText()+"','"+t5.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t1.setText("");t2.setText(""); t3.setText(""); t4.setText("");t5.setText("");
JOptionPane.showMessageDialog(this,"添加学生成功!","提示",RMATION_MESSAGE);}
}
if(e.getSource()==b2){
this.dispose();
GLXS js=new GLXS("管理学生界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}
}
class SCXS extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l;
JTextField t1;;
JButton b1,b2;
public SCXS(String str){
super(str);
p=new JPanel();
i=new ImageIcon("f679278ccfd256a4f11f361f[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
l1=new JLabel("学生学号");
t1=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(b1);
p.add(b2);

}
public void actionP
erformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")){JOptionPane.showMessageDialog(this,"学生学号不能为空!"

JAVA ,SQL server 数据库课程设计 学生选课系统

,"提示",JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="DELETE FROM 学生表 WHERE(学号='"+t1.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t1.setText("");
JOptionPane.showMessageDialog(this,"删除学生成功!","提示",RMATION_MESSAGE);}
}
if(e.getSource()==b2){
this.dispose();
GLXS js=new GLXS("管理学生界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}
}
class CXXS extends JFrame implements ActionListener{
JPanel p;
JButton b1;
MyTableModel12 mt;
JTable t;
JScrollPane s;
public CXXS(String str){
super(str);
setLayout(new BorderLayout());
mt=new MyTableModel12();
t=new JTable(mt);
s=new JScrollPane(t);
p=new JPanel();
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,10));
b1=new JButton("返回上级");
b1.addActionListener(this);
p.add(b1);
add(p,"South");
add(s,"Center");
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
GLXS js=new GLXS("管理学生界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}
}
class MyTableModel12 extends AbstractTableModel{
String xsnum,xsname,sex,age,profess;
final String[] columnNames={"学号","姓名","性别","年龄","专业"};
Object[][]data=new Object[100][5];
public MyTableModel12(){
int m=0;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e){
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql=sql="SELECT * FROM 学生表";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
xsnum=rs.getString(1);
xsname=rs.getString(2);
sex=rs.getString(3);
age=rs.getString(4);
profess=rs.getString(5);
data[m][0]=xsnum;data[m][1]=xsname;data[m][2]=sex;data[m][3]=age;data[m++][4]=profess;
}
stmt.close();
con.close();
}catch(SQLException e
){
}
}
public int getColumnCount(){
return columnNames.length;
}
public int getRowCount(){
return data.length;
}
public String getColum

JAVA ,SQL server 数据库课程设计 学生选课系统

nName(int col){
return columnNames[col];
}
public Object getValueAt(int row,int col){
return data[row][col];
}
public void setValueAt(Object value,int row,int col){
int numRows=getRowCount();
int numCols=getColumnCount();
for(int i=0;i<numRows;i++){
for(int j=0;j<numCols;j++){
System.out.print(" "+data[i][j]);
}
}
}
}

class TJKC extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l2,l3,l;
JTextField t1,t2,t3;
JButton b1,b2;
public TJKC(String str){
super(str);
p=new JPanel();
i=new ImageIcon("http_imgload[9].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,30));
l1=new JLabel("课程号");
l2=new JLabel("课程名");
l3=new JLabel("学 分");
t1=new JTextField("",10);
t2=new JTextField("",10);
t3=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")){JOptionPane.showMessageDialog(this,"课程号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="INSERT INTO 课程表(课程号,课程名,学分) VALUES('"+t1.getText()+"','"+t2.getText()+"','"+t3.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t1.setText("");t2.setText(""); t3.setText("");
JOptionPane.showMessageDialog(this,"添加课程成功!","提示",RMATION_MESSAGE);}
}
if(e.getSource()==b2){
this.dispose();
GLKC xs=new GLKC("管理课程界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
}
}

class SCKC extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l;
JTextField t1;;
JButton b1,b2;
public SCKC(String str){
super(str);
p
=new JPanel();
i=new ImageIcon("d198149725bbbf54d31b700a[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeig

JAVA ,SQL server 数据库课程设计 学生选课系统

ht());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
l1=new JLabel("该课程号");
t1=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")){JOptionPane.showMessageDialog(this,"课程号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="DELETE FROM 课程表 WHERE(课程号='"+t1.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t1.setText("");
JOptionPane.showMessageDialog(this,"删除课程成功!","提示",RMATION_MESSAGE);}
}
if(e.getSource()==b2){
this.dispose();
GLKC xs=new GLKC("管理课程界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);;
}
}
}
class CXKC extends JFrame implements ActionListener{
JPanel p;
JButton b1;
MyTableModel13 mt;
JTable t;
JScrollPane s;
public CXKC(String str){
super(str);
setLayout(new BorderLayout());
mt=new MyTableModel13();
t=new JTable(mt);
s=new JScrollPane(t);
p=new JPanel();
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,10));
b1=new JButton("返回上级");
b1.addActionListener(this);
p.add(b1);
add(p,"South");
add(s,"Center");
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
GLKC js=new GLKC("管理课程界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}
}
class MyTableModel13 extends AbstractTableModel{
String kcnum,kcname,score;
final String[] columnNames={"课程号","课程名","学分"};
Object[][]data=new Object[100][3];
public MyTableModel13(){
int m=0;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e){
}
try{
con=DriverManager.getConnection(url,"SQS","200628");

JAVA ,SQL server 数据库课程设计 学生选课系统

stmt=con.createStatement();
sql=sql="SELECT * FROM 课程表";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
kcnum=rs.getString(1);
kcname=rs.getString(2);
score=rs.getString(3);

data[m][0]=kcnum;data[m][1]=kcname;data[m++][2]=score;
}
stmt.close();
con.close();
}catch(SQLException e){
}
}
public int getColumnCount(){
return columnNames.length;
}
public int getRowCount(){
return data.length;
}
public String getColumnName(int col){
return columnNames[col];
}
public Object getValueAt(int row,int col){
return data[row][col];
}
public void setValueAt(Object value,int row,int col){

int numRows=getRowCount();
int numCols=getColumnCount();
for(int i=0;i<numRows;i++){
for(int j=0;j<numCols;j++){
System.out.print(" "+data[i][j]);
}
}
}
}
class JSDK extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l2,l;
JTextField t1,t2;
JButton b1,b2;
public JSDK(String str){
super(str);
p=new JPanel();
i=new ImageIcon("3f207a533aab04161138c212[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,50));
l1=new JLabel("教职工号");
l2=new JLabel("该课程号");
t1=new JTextField("",10);
t2=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);

}

public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")||t2.getText().equals("")){JOptionPane.showMessageDialog(this,"教职工号或课程号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="INSERT INTO 代课表 VALUES('"+t1.getText()+"','"+t2.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t1.setText("");t2.setText("");
JOptionPane.showMessageDialog(this,"教师代课成功!","提示",http://doc
.RMATION_MESSAGE);}
}
if(e.getSource()==b2){
this.dispose();
JS js=new JS("教师界面");
js.setLocation(400, 200);
js.setS

JAVA ,SQL server 数据库课程设计 学生选课系统

ize(500,300);
js.setVisible(true);
}
}
}
class DLJSXX extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l;
static JTextField t;
JButton b1,b2;
public DLJSXX(String str){
super(str);
p=new JPanel();
i=new ImageIcon("3f207a533aab04161138c212[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
l1=new JLabel("教职工号");
t=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t.getText().equals("")){JOptionPane.showMessageDialog(this,"教职工号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{
this.dispose();
JSXX gly=new JSXX("教师信息界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);}
}
if(e.getSource()==b2){
this.dispose();
JS js=new JS("教师界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}
}
class MyTableModel1 extends AbstractTableModel{
String jsnum,jsname,sex,age,work,kcnum,kcname,score;
final String[] columnNames={"教职工号","姓名","性别","年龄","职称","课程号","课程名","学分"};
Object[][]data=new Object[100][8];
public MyTableModel1(){
int m=0;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e){
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="SELECT * FROM 教师_课程 WHERE 教职工号='"+DLJSXX.t.getText()+"'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
jsnum=rs.getString(1);
jsname=rs.getString(2);
sex=rs.getString(3);
age=rs.getString(4);
work=rs.getString(5);
kcnum=rs.getString(6);
kcname=rs.getString(7);
score=rs.getString(8);
data[m][0]=jsnum;data[m][1]=jsname;data[m][2]=sex;data[m][3]=age;data[m][4]=work;data[m][5]=kcnum;data[m][6]=kcname;data[m++][7]=score;
}
stmt.close();
con.close();
}catch(SQLException e){
}
}
public int getColumnCount(){
return columnNames.length;
}
public int getRowCount(){
return
data.length;
}
public String getColumnName(int col){
return columnNames[col];
}
public Object getValueAt(int row,int col){
return data[row

JAVA ,SQL server 数据库课程设计 学生选课系统

][col];
}
public void setValueAt(Object value,int row,int col){

int numRows=getRowCount();
int numCols=getColumnCount();
for(int i=0;i<numRows;i++){
for(int j=0;j<numCols;j++){
System.out.print(" "+data[i][j]);
}
}
}
}
class JSXX extends JFrame implements ActionListener{
JPanel p;
JButton b1;
MyTableModel1 mt;
JTable t;
JScrollPane s;
public JSXX(String str){
super(str);
setLayout(new BorderLayout());
mt=new MyTableModel1();
t=new JTable(mt);
s=new JScrollPane(t);
p=new JPanel();
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,10));
b1=new JButton("返回上级");
b1.addActionListener(this);
p.add(b1);
add(p,"South");
add(s,"Center");
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dispose();
DLJSXX js=new DLJSXX("查询自己信息界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}
}



class XSXK extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l2,l;
JTextField t1,t2;
JButton b1,b2;
public XSXK(String str){
super(str);
p=new JPanel();
i=new ImageIcon("http_imgload[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,50));
l1=new JLabel("学生学号");
l2=new JLabel("该课程号");
t1=new JTextField("",10);
t2=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t1.getText().equals("")||t2.getText().equals("")){JOptionPane.showMessageDialog(this,"学生学号或课程号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e1){
e1.printStackTrace();
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="INSERT INTO 选课表 VALUES('"+t1.getText()+"','"+t2.getText()+"')";
stmt.executeUpdate(sql);
stmt.close();
con.close();
}catch(SQLException e2){
e2.printStackTrace();
}
t
1.setText("");t2.setText("");
JOptionPane.showMessageDialog(this,"学生选课成功!","提示",

JAVA ,SQL server 数据库课程设计 学生选课系统

RMATION_MESSAGE);}
}
if(e.getSource()==b2){
this.dispose();
XS xs=new XS("学生界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
}
}
class DLXSXX extends JFrame implements ActionListener{
JPanel p;
ImageIcon i;
JLabel l1,l;
static JTextField t;
JButton b1,b2;
public DLXSXX(String str){
super(str);
p=new JPanel();i=new ImageIcon("a63e9ee8678507772797911b[1].jpg");
l=new JLabel(i);
l.setBounds(0, 0,i.getIconWidth(),i.getIconHeight());
getLayeredPane().add(l, new Integer(Integer.MIN_VALUE));
p=(JPanel) this.getContentPane();
p.setOpaque(false);
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,70));
l1=new JLabel("学生学号");
t=new JTextField("",10);
b1=new JButton("确定");
b2=new JButton("返回");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(l1);
p.add(t);
p.add(b1);
p.add(b2);

}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
if(t.getText().equals("")){JOptionPane.showMessageDialog(this,"学生学号不能为空!","提示",JOptionPane.WARNING_MESSAGE);}
else{ this.dispose();
XSXX gly=new XSXX("学生信息界面");
gly.setLocation(400, 200);
gly.setSize(500,300);
gly.setVisible(true);}
}
if(e.getSource()==b2){
this.dispose();
XS xs=new XS("学生界面");
xs.setLocation(400, 200);
xs.setSize(500,300);
xs.setVisible(true);
}
}
}
class MyTableModel2 extends AbstractTableModel{
String xsnum,xsname,sex,age,profess,kcnum,kcname,score;
final String[] columnNames={"学号","姓名","性别","年龄","专业","课程号","课程名","学分"};
Object[][]data=new Object[100][8];
public MyTableModel2(){
int m=0;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=学生选课系统";
Connection con;
String sql;
Statement stmt;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ng.ClassNotFoundException e){
}
try{
con=DriverManager.getConnection(url,"SQS","200628");
stmt=con.createStatement();
sql="SELECT * FROM 学生_课程 WHERE 学号='"+DLXSXX.t.getText()+"'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
xsnum=rs.getString(1);
xsname=rs.getString(2);
sex=rs.getString(3);
age=rs.getString(4);
profess=rs.getString(5);
kcnum=rs.getString(6);
kcname=rs.getString(7);
score=rs.getString(8);
data[m][0]=xsnum;data[m][1]=xsname;data[m][2]=sex;data[m][3]=age;data[m][4]=profess;data[m][5]=kcnum;data[m][6]=kcname;data[m++][7]=score;
}
stmt.close();
con.close();
}catch(SQLException e){
}
}
public int getColumnCount(){
return columnNames.length;
}
public int getRowCount(){
return dat

JAVA ,SQL server 数据库课程设计 学生选课系统

a.length;
}
public String getColumnName(int col){
return columnNames[col];
}
public Object getValueAt(int row,int col){
return data[row][col];
}
public void setValueAt(Object value,int row,int col){

int numRows=getRowCount();
int numCols=getColumnCount();
for(int i=0;i<numRows;i++){
for(int j=0;j<numCols;j++){
System.out.print(" "+data[i][j]);
}
}
}
}
class XSXX extends JFrame implements ActionListener{
JPanel p;
JButton b1;
MyTableModel2 mt;
JTable t;
JScrollPane s;
public XSXX(String str){
super(str);
setLayout(new BorderLayout());
mt=new MyTableModel2();
t=new JTable(mt);
s=new JScrollPane(t);
p=new JPanel();
p.setLayout(new FlowLayout(FlowLayout.CENTER,110,10));
b1=new JButton("返回上级");
b1.addActionListener(this);
p.add(b1);
add(p,"South");
add(s,"Center");
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
this.dis
pose();
DLXSXX js=new DLXSXX("查询自己信息界面");
js.setLocation(400, 200);
js.setSize(500,300);
js.setVisible(true);
}
}
}





本文来源:https://www.bwwdw.com/article/a9tq.html

Top