资源描述
一、
(1) 首先确定学生管理系统的用户。
(2) 学生管理系统的用户基本分为两类,分别是老师和学生。不管是哪种用户都是必须经过登录才能进入学生管理系统的,所以该系统必须有一个登录界面,并且在该界面中能够让用户选择用户是老师还是学生。该系统是不会对外开放的,所以也不存在注册界面。
(3) 因为用户分为两种,所以每一种用户进行操作的界面应该是不同的。首先是学生界面,在其中应该只有查询成绩和个人信息查询和插入。主要来学习如何进行学生界面开发。
(4) 除了学生界面外,还要有一个老师界面。老师在老师界面中可以对学生信息进行管理,包括查询、修改和删除。同样也可以对学生的成绩进行管理,包括查询和插入,由于输入错误还要能够对学生的成绩进行修改,由于学生作弊还能够将学生的成绩进行删除。
(5) 首先数据库中应该有老师和学生这两个表,表中应该最少有用户名和密码两项,使用表中的这两项就可以进行登录。在学生表中还应该具有一些和学籍相关的信息,包括年龄、班级等内容,这样就可以在系统中对学生信息进行操作。
(6) 除此之外还需要一个成绩表,通过该表老师可以对学生的成绩进行查询、插入、修改和删除。学生也可以通过该表对自己的成绩进行查询。
(7) 不管是老师和学生进入学生管理系统都是从登录界面进入的。在登录界面中应该是让用户选择自己身份的,然后系统将根据用户的选择来判断用户的身份并进行查询不同的数据库。
(8) 对界面设计好基本形式后,就可以进行程序开发。首先要定义两个标签和两个文本框,分别来表示用户名和密码。并且还需要定义一个下拉列表让用户来进行身份选择,其中选项包括“学生”和“老师”。在程序的最后还定义了两个按钮,从而让用户输入用户名和密码后进行登录。
(9) 在学生界面中,学生可以对自己的信息进行查询,在第一次登录时还可以对自己的信息进行插入,并且学生能够查询自己的成绩。
(10) 因为学生要完成对信息和成绩的操作,所以这里的设计是在界面中定义两个菜单,分别进行信息和成绩的操作。因为对信息的操作包括插入和查询,所以还需要在信息菜单下定义“插入”和“查询”两个子菜单。
(11) 对界面进行设计后,就可以进行程序开发。同样首先是创建一个窗口,在窗口中要创建两个菜单,并且在信息菜单下还要创建“插入”和“查询”两个子菜单。
(12) 在学生界面中单击“信息”菜单下的“插入”子菜单,就会进入学生插入界面,在该界面中学生可以输入自己的信息。
(13) 学生第一次插入信息后,老师是可以对学生的信息进行修改和删除的。除此之外,学生还可以查询自己被修改后的信息,在信息菜单下有一个查询子菜单,单击该菜单就触发事件,从而进入查询学生信息界面。
(14) 在学生界面中还有一个“成绩”菜单,在学生的界面该菜单下只有一个“查询”子菜单。单击“查询”子菜单,将触发事件,进入到查询成绩界面。
2、 附录
(1) 登陆界面
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class systems extends JFrame implements ActionListener
{
static systems ss;
JPanel panel = new JPanel();
JLabel label1 = new JLabel("输入姓名:");
JTextField name = new JTextField();
JLabel label2 = new JLabel("密 码:");
JPasswordField pwd = new JPasswordField();
JButton Enter = new JButton("登录");
JButton Exit = new JButton("退出");
String url = "D:\\Systems\\title.jpg";
ButtonGroup bgp = new ButtonGroup();
JRadioButton stu = new JRadioButton("学生");
JRadioButton tch = new JRadioButton("教师");
public systems()
{
super("登录系统");
this.setResizable(false);
JLabel img = new JLabel(new ImageIcon(url));
img.setBounds(0,0,500,100);
panel.add(img);
stu.setBounds(165,210,70,20);
tch.setBounds(265,210,70,20);
bgp.add(stu);
bgp.add(tch);
panel.add(stu);
panel.add(tch);
Enter.setBounds(150,250,80,20);
Exit.setBounds(270,250,80,20);
Enter.addActionListener(this);
Exit.addActionListener(this);
panel.add(Enter);
panel.add(Exit);
panel.setLayout(null);
this.add(panel);
label1.setBounds(135,130,100,25);
panel.add(label1);
name.setBounds(265,130,100,25);
panel.add(name);
label2.setBounds(135,165,100,25);
panel.add(label2);
pwd.setBounds(265,165,100,25);
panel.add(pwd);
this.setBounds(100,100,500,350);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Enter)
{
String username , password;
username = name.getText();
password = pwd.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce)
{
JOptionPane.showMessageDialog(ss,ce.getMessage());
}
if(stu.isSelected())
{
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:sysdb","sa","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from STU");
while(rs.next())
{
if((rs.getString("ID").equals(username))&&(rs.getString("Pwd").equals(password)))
{
JOptionPane.showMessageDialog(ss,"登陆成功");
Students stu = new Students();
}
else
{
JOptionPane.showMessageDialog(ss,"登录失败");
}
}
rs.close();
stmt.close();
}
catch (SQLException se)
{
JOptionPane.showMessageDialog(ss,se.getMessage());
}
}
else if(tch.isSelected())
{
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:systchdb","sa","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from TCH");
while(rs.next())
{
if((rs.getString("ID").equals(username))&&(rs.getString("Pwd").equals(password)))
{
JOptionPane.showMessageDialog(ss,"登陆成功");
}
else
{
JOptionPane.showMessageDialog(ss,"登录失败");
}
}
}
catch (SQLException se)
{
JOptionPane.showMessageDialog(ss,se.getMessage());
}
}
}
else
{
System.exit(0);
}
}
public static void main(String[] args)
{
systems sys = new systems();
}
}
(2) 学生界面
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Students extends JFrame implements ActionListener
{
JMenuBar jmb = new JMenuBar();
JMenu Message = new JMenu("信息");
JMenu Score = new JMenu("成绩");
JMenuItem Item1 = new JMenuItem("插入");
JMenuItem Item2 = new JMenuItem("查询");
JMenuItem Item3 = new JMenuItem("查询");
public Students()
{
super("学生界面");
this.setSize(500,400);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setJMenuBar(jmb);
jmb.add(Message);
jmb.add(Score);
Message.add(Item1);
Message.add(Item2);
Score.add(Item3);
Item1.addActionListener(this);
Item2.addActionListener(this);
Item3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Item1)
{
AddMsg ad = new AddMsg();
}
else if(e.getSource()==Item2)
{
Serch ser = new Serch();
}
else
{
Score so = new Score();
}
}
public static void main(String[] args)
{
Students stu = new Students();
}
}
(3) 添加学生信息
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class AddMsg extends JFrame implements ActionListener
{
static AddMsg s;
/*添加学生信息控件*/
JPanel jpl = new JPanel();
JLabel label1 = new JLabel("添加基本信息",JLabel.CENTER);
JLabel label2 = new JLabel("学号:",JLabel.CENTER);
JLabel label3 = new JLabel("姓名:",JLabel.CENTER);
JLabel label4 = new JLabel("性别:",JLabel.CENTER);
JLabel label5 = new JLabel("班级:",JLabel.CENTER);
JLabel label6 = new JLabel("学院:",JLabel.CENTER);
JTextField num = new JTextField(2);
JTextField nam = new JTextField(4);
ButtonGroup bgp = new ButtonGroup();
JRadioButton man = new JRadioButton("男");
JRadioButton women = new JRadioButton("女");
JTextField clas = new JTextField();
JTextField scl = new JTextField();
JButton reset = new JButton("重置");
JButton addmsg = new JButton("添加");
public AddMsg()
{
super("添加学生信息");
this.setResizable(false);
this.setSize(500,400);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(jpl);
jpl.setLayout(null);
addmsg.addActionListener(this);
reset.addActionListener(this);
/*插入面板*/
label1.setBounds(100,20,300,20);
jpl.add(label1);
label2.setBounds(100,50,70,20);
jpl.add(label2);
num.setBounds(190,50,140,20);
jpl.add(num);
label3.setBounds(100,90,70,20);
jpl.add(label3);
nam.setBounds(190,90,140,20);
jpl.add(nam);
label4.setBounds(100,130,70,20);
jpl.add(label4);
man.setBounds(190,130,60,20);
women.setBounds(270,130,60,20);
jpl.add(man);
jpl.add(women);
bgp.add(man);
bgp.add(women);
label5.setBounds(100,170,70,20);
jpl.add(label5);
clas.setBounds(190,170,140,20);
jpl.add(clas);
label6.setBounds(100,210,70,20);
jpl.add(label6);
scl.setBounds(190,210,140,20);
jpl.add(scl);
reset.setBounds(120,250,90,20);
addmsg.setBounds(240,250,90,20);
jpl.add(reset);
jpl.add(addmsg);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==addmsg)
{
String sex;
if(man.isSelected())
{
sex="男";
}
else
{
sex="女";
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce)
{
JOptionPane.showMessageDialog(s,ce.getMessage());
}
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:sysdb","sa","");
Statement stmt = con.createStatement();
int a = stmt.executeUpdate("insert into STU(ID , Pwd , Name , Sex , Class , Collage)values('"+num.getText()+"','"+"12345678','"+nam.getText()+"','"+sex+"','"+clas.getText()+"','"+scl.getText()+"')");
if(a==1)
{
JOptionPane.showMessageDialog(s,"已成功添加");
}
else
{
JOptionPane.showMessageDialog(s,"添加失败");
}
stmt.close();
}
catch (SQLException se)
{
JOptionPane.showMessageDialog(s,se.getMessage());
}
}
else
{
num.setText("");
nam.setText("");
clas.setText("");
scl.setText("");
num.requestFocus();
}
}
public static void main(String[] args)
{
AddMsg amg = new AddMsg();
}
}
(4) 添加学生成绩
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class Addscore extends JFrame implements ActionListener
{
static Addscore ss;
JLabel[] label = {new JLabel("学号:") , new JLabel("计算机网络:") , new JLabel("Linux操作系统:") , new JLabel("计算机专业英语:") , new JLabel("计算机信息技术基础:") , new JLabel("Java程序设计:") , new JLabel("数据库应用实训教程:") , new JLabel("高等数学:") , new JLabel("XML:")};
JTextField[] txt = {new JTextField() , new JTextField() , new JTextField() , new JTextField() , new JTextField() ,new JTextField() , new JTextField() ,new JTextField() ,new JTextField() };
JButton add = new JButton("添加");
JButton reset = new JButton("重置");
JPanel jpl = new JPanel();
JLabel title = new JLabel("添加学生成绩" , JLabel.CENTER);
Font f = new Font("黑体" , Font.BOLD , 16 );
int s = 100;
public Addscore()
{
super("添加学生信息");
this.setResizable(false);
this.setSize(500,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.add(jpl);
add.addActionListener(this);
reset.addActionListener(this);
jpl.setLayout(null);
title.setBounds(150,40,200,20);
title.setFont(f);
title.setForeground(Color.red);
jpl.setBackground(Color.LIGHT_GRAY);
jpl.add(title);
for(int i = 0 ; i <label.length ; i++)
{
label[i].setBounds(100,s,140,20);
jpl.add(label[i]);
txt[i].setBounds(260,s,140,20);
jpl.add(txt[i]);
s=s+40;
}
add.setBounds(150,s,80,20);
reset.setBounds(250,s,80,20);
jpl.add(add);
jpl.add(reset);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==add)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce)
{
JOptionPane.showMessageDialog(ss,ce.getMessage());
}
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:sysdb","sa","");
Statement stmt = con.createStatement();
int a = stmt.executeUpdate("insert into 计算机系成绩(SID , 计算机网络 , Linux操作系统 , 计算机专业英语 , 计算机信息技术基础 , Java程序设计 , 数据库应用实训教程 , 高等数学 , Xml)values('"+txt[0].getText()+"','"+txt[1].getText()+"','"+txt[2].getText()+"','"+txt[3].getText()+"','"+txt[4].getText()+"','"+txt[5].getText()+"','"+txt[6].getText()+"','"+txt[7].getText()+"','"+txt[8].getText()+"')");
if(a==1)
{
JOptionPane.showMessageDialog(ss,"添加成功");
}
else
{
JOptionPane.showMessageDialog(ss,"添加失败");
}
}
catch (SQLException se)
{
JOptionPane.showMessageDialog(ss,se.getMessage());
}
}
else
{
for(int i = 0 ; i<txt.length ; i++)
{
txt[i].setText("");
txt[0].requestFocus();
}
}
}
public static void main(String[] args)
{
Addscore as = new Addscore();
}
}
(5) 查询学生信息
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
public class Serch extends JFrame implements ActionListener
{
/*查询学生信息控件*/
static Serch s;
JPanel jpl = new JPanel();
JLabel SCH = new JLabel("查询学生信息",JLabel.CENTER);
JLabel label1 = new JLabel("请输入学号:",JLabel.CENTER);
JButton serch = new JButton("查询");
JLabel label2 = new JLabel("姓名:",JLabel.CENTER);
JLabel label3 = new JLabel("班级:",JLabel.CENTER);
JLabel label4 = new JLabel("学校:",JLabel.CENTER);
JLabel label5 = new JLabel("性别:",JLabel.CENTER);
ButtonGroup bgp = new ButtonGroup();
JRadioButton man = new JRadioButton("男");
JRadioButton women = new JRadioButton("女");
JTextField num = new JTextField();
JTextField nam = new JTextField();
JTextField clas = new JTextField();
JTextField scl = new JTextField();
JButton reset = new JButton("重置");
public Serch()
{
this.setSize(500,400);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(jpl);
jpl.setLayout(null);
serch.addActionListener(this);
reset.addActionListener(this);
/*查询面板*/
SCH.setBounds(100,20,300,20);
jpl.add(SCH);
label1.setBounds(100,60,100,20);
jpl.add(label1);
num.setBounds(220,60,140,20);
jpl.add(num);
serch.setBounds(120,100,90,20);
reset.setBounds(260,100,90,20);
jpl.add(serch);
jpl.add(reset);
label2.setBounds(100,140,70,20);
jpl.add(label2);
nam.setBounds(190,140,140,20);
jpl.add(nam);
label5.setBounds(100,180,70,20);
jpl.add(label5);
man.setBounds(205,180,60,20);
women.setBounds(285,180,60,20);
bgp.add(man);
bgp.add(women);
jpl.add(man);
jpl.add(women);
label3.setBounds(100,220,70,20);
jpl.add(label3);
clas.setBounds(190,220,140,20);
jpl.add(clas);
label4.setBounds(100,260,70,20);
jpl.add(label4);
scl.setBounds(190,260,140,20);
jpl.add(scl);
}
public void actionPerformed(ActionEvent e)
{
String id = num.getText();
if(e.getSource()==serch)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce)
{
JOptionPane.showMessageDialog(s,ce.getMessage());
}
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:sysdb","sa","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from STU where ID = '" + id + "'");
while(rs.next())
{
nam.setText(rs.getString("Name"));
if(rs.getString("Sex").equals("男"))
{
man.setSelected(true);
}
else
{
women.setSelected(true);
}
clas.setText(rs.getString("Class"));
scl.setText(rs.getString("Collage"));
}
}
catch (SQLException se)
{
JOptionPane.showMessageDialog(s,se.getMessage());
}
}
}
public static void main(String[] args)
{
Serch sch = new Serch();
}
}
(6) 查询成绩
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.font.*;
import java.sql.*;
public class Score extends JFrame implements ActionListener
{
static Score s;
JLabel title = new JLabel("查询成绩",JLabel.CENTER);
Font f = new Font("楷
展开阅读全文