中南民族大学管理学院
学生课程设计报告
课程名称: Java语言课程设计
题 目:学生成绩管理系统
年 级: 2010
专 业:信息管理与信息系统
学 号: 。。。。。。。。
姓 名: SP_LJH
指导教师: 张 晴
完成地点:管理学院综合实验室
完成日期:
20 12 学年至20 13 学年度第 1 学期
目录
1题目描述和分析......................................................1
2问题分解............................................................1
3类(数据、方法)的设计..............................................2
4编码……………………………………………………………………………………3
5测试……………………………………………………………………………………3
6操作使用说明…………………………………………………………………………6
7难点及关键技术分析…………………………………………………………………6
8心得体会………………………………………………………………………………6
9.附录……………………………………………………………………………………7
10指导老师批阅…………………………………………………………………………31
1题目描述和分析
一个图形用户界面,有两种权限登录方式,分别是老师和学生。
老师登录系统能够查看学生的成绩以及一些基本的学生信息。如:学号,姓名,各科成绩。老师还能够在该系统里修改学生的成绩,登记学生的成绩。能按学号删除学生的记录,成绩等。
学生登录该系统只能够查看自己的成绩,不能修改自己的成绩。
该系统的登录都需要账号密码才能够修改和查看。在登录以前先选择好是老师登录还是学生登录,然后进入不同的页面行使不同的权限。
该系统需要与数据库连接才能够完成上述的功能。
2问题分解
3类的设计
本程序由于要用到图形用户界面所以用到了包有java.awt.*, java.awt.event.*, javax.swing.* 。 还连接了Microsoft SQL Server 所以还用到的包有连接数据库的包有 java.sql.Connection, java.sql.DriverManager,java.sql.ResultSet, java.sql.SQLException, java.sql.Statement。
类及其作用如下表:
SQL Server2008里有三张表:
4编码
见附录1.
5测试和发布
运行程序之后选择登录窗口:
选择老师登录与学生登录之后的页面:
老师登录之后的选择操作页面
学生登录之后的选择操作页面
添加操作
删除操作
修改操作
查询操作
6操作使用说明
首先运行程序进入主界面:主界面选择登录身份—老师,学生。
当选择老师登录输入在数据库中表teacher里的帐号密码之后进入老师的操作界面,在这个界面老师可以选择的操作有添加,删除,修改,查询等操作。这些操作只要输入正确的学生学号及在数据库chengjibiao里的学号,就能进行相应的操作。
当选择学生登录输入在数据库表student里的帐号密码之后进入学生的操作界面,在这个界面的学生只能进行查选操作,输入在数据库表chengjibiao里的正确学号就能查询相应的学号对应的信息。
7难点及关键技术分析
程序的难点是与数据库的连接上有点繁琐,在经过我在网上看到的很多资料之后把数据库与程序成功的连接了。
程序存在的不足是程序的界面还不美观,看着不漂亮。
8心得体会
通过这次课程设计我学会了使用Eclipse,还有Eclipse与Microsoft SQL Server 2008的连接。通过这次JAVA课程设计自己感觉自己的编程技巧有了一定的提高。
9附录:程序代码
包
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
主类
publicclass Chengjiguanli {
publicstaticvoid main(String[] args) {
new xuanzedenglu();
}
}
选择身份登录的窗口
classxuanzedengluextends JFrame implements ActionListener {
JFrame frame = new JFrame("选择登录窗口");
JPanel imagePanel;
ImageIcon bg;
Button button1, button2;
Box box;
Label label;
Panel p1;
xuanzedenglu() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
p1 = new Panel();
label = new Label("成绩管理系统", Label.CENTER);
label.setFont(new Font("隶书", Font.BOLD, 30));
label.setBackground(Color.green);
p1.add(label);
button1 = new Button("老师");
button2 = new Button("学生");
box = Box.createHorizontalBox();
box.add(button1);
box.add(Box.createHorizontalStrut(8));
box.add(button2);
button1.addActionListener(this);
button2.addActionListener(this);
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
bg = new ImageIcon("2.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1, BorderLayout.NORTH);
imagePanel.add(box, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭后状态
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(200, 200, 500, 300);
frame.setResizable(false);//设置窗口大小不可改变
frame.setVisible(true);
validate();
}
publicvoid actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
new laoshidenglu();
}
if (e.getSource() == button2) {
new xueshengdenglu();
}
}
}
老师登录窗口
classlaoshidengluextends JFrame implements ActionListener {
JFrame frame = new JFrame("登陆界面");
JPanel imagePanel;
ImageIcon bg;
Button button1, button2;
Label l1, l2, l3;
TextField a1, a2;
Box b1, b2, b3, b4, b5;
Connection con;
Statement sql;
ResultSet rs;
laoshidenglu() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
button1 = new Button("登陆");
button2 = new Button("退出");
Panel p1 = new Panel();
l1 = new Label("学生成绩管理系统", Label.CENTER);
l1.setFont(new Font("隶书", Font.BOLD, 40));
l1.setBackground(Color.green);
p1.add(l1);
l2 = new Label("登录名");
l3 = new Label("密码");
a1 = new TextField(10);
a2 = new TextField(10);
a2.setEchoChar('*');
b1 = Box.createVerticalBox();
b1.add(l2);
b1.add(Box.createVerticalStrut(8));
b1.add(l3);
b2 = Box.createVerticalBox();
b2.add(a1);
b2.add(Box.createVerticalStrut(8));
b2.add(a2);
b3 = Box.createHorizontalBox();
b3.add(b1);
b3.add(Box.createHorizontalStrut(10));
b3.add(b2);
b4 = Box.createHorizontalBox();
b4.add(button1);
b4.add(Box.createHorizontalStrut(10));
b4.add(button2);
b5 = Box.createVerticalBox();
b5.add(b3);
b5.add(Box.createVerticalStrut(8));
b5.add(b4);
button1.addActionListener(this);
button2.addActionListener(this);
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
bg = new ImageIcon("1.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1, BorderLayout.NORTH);
imagePanel.add(b5, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(200, 150, 510, 340);
frame.setResizable(false);//设置窗口大小不可改变
frame.setVisible(true);
validate();
}
publicvoid actionPerformed(ActionEvent e) {
booleanboo = true;
if (e.getSource() == button2) {
System.exit(0);
}
if (e.getSource() == button1) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException eee) {
System.out.println("" + eee);
}
try {
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=学生成绩管理系统", "sa", "55151777");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM teacher ");
while (rs.next()) {
String username = rs.getString("username");
String password = rs.getString("password");
if (a1.getText().equals(username.trim())&&a2.getText().equals(password.trim())) {
boo = false;
new laoshichuangkou();
frame.dispose();
}else {
JOptionPane.showMessageDialog(this, "账户密码错误,请重新输入!!");
}
}
con.close();
} catch (SQLException eee) {
System.out.println(eee);
}
}
}
}
老师选择操作窗口
class laoshichuangkou extends JFrame implements ActionListener {
privatestaticfinallongserialVersionUID = 1L;
JFrame frame = new JFrame("选择窗口");
JPanel imagePanel;
ImageIcon bg;
Button button1, button2, button3, button4, button5, button6;
Box box;
Label label;
Panel p1;
laoshichuangkou() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
p1 = new Panel();
label = new Label("欢迎使用成绩管理系统", Label.CENTER);
label.setFont(new Font("隶书", Font.BOLD, 30));
label.setBackground(Color.green);
p1.add(label);
button1 = new Button("添加");
button2 = new Button("删除");
button3 = new Button("修改");
button4 = new Button("查询");
button5 = new Button("返回");
button6 = new Button("退出");
box = Box.createHorizontalBox();
box.add(button1);
box.add(Box.createHorizontalStrut(8));
box.add(button2);
box.add(Box.createHorizontalStrut(8));
box.add(button3);
box.add(Box.createHorizontalStrut(8));
box.add(button4);
box.add(Box.createHorizontalStrut(8));
box.add(button5);
box.add(Box.createHorizontalStrut(8));
box.add(button6);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
bg = new ImageIcon("2.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1, BorderLayout.NORTH);
imagePanel.add(box, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭后状态
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(200, 200, 500, 300);
frame.setResizable(false);//设置窗口大小不可改变
frame.setVisible(true);
validate();
}
publicvoid actionPerformed(ActionEvent e) {
if (e.getSource() == button6) {
System.exit(0);
}
if (e.getSource() == button1) {
new charu();
}
if (e.getSource() == button2) {
new shanchu();
}
if (e.getSource() == button3) {
new xiugai();
}
if (e.getSource() == button4) {
new chaxun();
}
if (e.getSource() == button5) {
new xuanzedenglu();
frame.dispose();
} else {
}
}
}
学生登录窗口
classxueshengdengluextends JFrame implements ActionListener {
JFrame frame = new JFrame("学生登陆界面");
JPanel imagePanel;
ImageIcon bg;
Button button1, button2;
Label l1, l2, l3;
TextField a1, a2;
Box b1, b2, b3, b4, b5;
Connection con;
Statement sql;
ResultSet rs;
xueshengdenglu() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
button1 = new Button("登陆");
button2 = new Button("退出");
Panel p1 = new Panel();
l1 = new Label("学生成绩管理系统", Label.CENTER);
l1.setFont(new Font("隶书", Font.BOLD, 40));
l1.setBackground(Color.green);
p1.add(l1);
l2 = new Label("登录名");
l3 = new Label("密码");
a1 = new TextField(10);
a2 = new TextField(10);
a2.setEchoChar('*');
b1 = Box.createVerticalBox();
b1.add(l2);
b1.add(Box.createVerticalStrut(8));
b1.add(l3);
b2 = Box.createVerticalBox();
b2.add(a1);
b2.add(Box.createVerticalStrut(8));
b2.add(a2);
b3 = Box.createHorizontalBox();
b3.add(b1);
b3.add(Box.createHorizontalStrut(10));
b3.add(b2);
b4 = Box.createHorizontalBox();
b4.add(button1);
b4.add(Box.createHorizontalStrut(10));
b4.add(button2);
b5 = Box.createVerticalBox();
b5.add(b3);
b5.add(Box.createVerticalStrut(8));
b5.add(b4);
button1.addActionListener(this);
button2.addActionListener(this);
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
bg = new ImageIcon("1.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1, BorderLayout.NORTH);
imagePanel.add(b5, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(200, 150, 510, 340);
frame.setResizable(false);//设置窗口大小不可改变
frame.setVisible(true);
validate();
}
publicvoid actionPerformed(ActionEvent e) {
booleanboo = true;
if (e.getSource() == button2) {
System.exit(0);
}
if (e.getSource() == button1) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException eee) {
System.out.println("" + eee);
}
try {
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=学生成绩管理系统", "sa", "55151777");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM student ");
while (rs.next()) {
String username = rs.getString("username");
String password = rs.getString("password");
if(a1.getText().equals(username.trim())&&a2.getText().equals(password.trim())){ //if。。。 else 。。 有问题!!!!
boo = false;
new chuangkou();
frame.dispose();
//System.out.println("aa");
}else{
JOptionPane.showMessageDialog(this, "账户密码错误,请重新输入!!");
//System.out.println("bb");
}
}
con.close();
} catch (SQLException eee) {
System.out.println(eee);
}
}
}
}
学生选择操作窗口
classchuangkouextends JFrame implements ActionListener {
JFrame frame = new JFrame("选择窗口");
JPanel imagePanel;
ImageIcon bg;
Button button4, button5, button6;
Box box;
Label label;
Panel p1;
chuangkou() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
p1 = new Panel();
label = new Label("欢迎使用成绩管理系统", Label.CENTER);
label.setFont(new Font("隶书", Font.BOLD, 30));
label.setBackground(Color.green);
p1.add(label);
button4 = new Button("查询");
button5 = new Button("返回");
button6 = new Button("退出");
box = Box.createHorizontalBox();
box.add(Box.createHorizontalStrut(8));
box.add(button4);
box.add(Box.createHorizontalStrut(8));
box.add(button5);
box.add(Box.createHorizontalStrut(8));
box.add(button6);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
bg = new ImageIcon("2.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1, BorderLayout.NORTH);
imagePanel.add(box, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭后状态
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(200, 200, 500, 300);
frame.setResizable(false);//设置窗口大小不可改变
frame.setVisible(true);
validate();
}
publicvoid actionPerformed(ActionEvent e) {
if (e.getSource() == button6) {
System.exit(0);
}
if (e.getSource() == button4) {
new chaxun();
}
if (e.getSource() == button5) {
new xuanzedenglu();
frame.dispose();
} else {
}
}
}
添加,删除,修改,查询操作
/*
* 添加数据界面
*/
classcharuextends JFrame implements ActionListener {
JFrame frame = new JFrame("添加数据");
JPanel imagePanel;
ImageIcon bg;
Button sure;
TextField input1, input2, input3, input4, input5;
TextArea show;
Box box1, box2, box3, box4;
int k, s1, j;
Connection con;
Statement sql;
ResultSet rs;
charu() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
input1 = new TextField(10);
input2 = new TextField(10);
input3 = new TextField(10);
input4 = new TextField(10);
input5 = new TextField(10);
box2 = Box.createVerticalBox();
box2.add(input1);
box2.add(Box.createVerticalStrut(8));
box2.add(input2);
box2.add(Box.createVerticalStrut(8));
box2.add(input3);
box2.add(Box.createVerticalStrut(8));
box2.add(input4);
box2.add(Box.createVerticalStrut(8));
box2.add(input5);
box1 = Box.createVerticalBox();
box1.add(new Label("学号:"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("姓名:"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("生日:"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("数学:"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("英语:"));
box3 = Box.createHorizontalBox();
box3.add(box1);
box3.add(Box.createHorizontalStrut(1));
box3.add(box2);
show = new TextArea(6, 43);
sure = new Button("确定");
box4 = Box.createHorizontalBox();
Label label1 = new Label("请输入数据");
label1.setFont(new Font("宋体", Font.BOLD, 20));
label1.setForeground(Color.blue);
box4.add(label1);
box4.add(Box.createHorizontalStrut(1));
box4.add(sure);
sure.addActionListener(this);
bg = new ImageIcon("3.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
show.setEditable(false);
imagePanel.add(box4, BorderLayout.NORTH);
imagePanel.add(box3, BorderLayout.CENTER);
imagePanel.add(show, BorderLayout.SOUTH);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(700, 200, 540, 440);
frame.setResizable(false);
frame.setVisible(true);
validate();
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
}
publicvoid actionPerformed(ActionEvent ee) {
String s1, s2, s3, s4, s5, insert1, recode, name, date, number;
int m1, m2, math, english;
s1 = input1.getText();
s2 = input2.getText();
s3 = input3.getText();
s4 = input4.getText();
s5 = input5.getText();
number = s1;
name = s2;
date = s3;
m1 = Integer.parseInt(s4);
math = m1;
m2 = Integer.parseInt(s5);
english = m2;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException eee) {
System.out.println("" + eee);
}
try {
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=学生成绩管理系统", "sa", "55151777");
sql = con.createStatement();
recode = "(" + "'" + number + "'" + "," + "'" + name + "'" + ","
+ "'" + date + "'" + "," + math + "," + english + ")";
insert1 = "INSERT INTO chengjibiao VALUES " + recode;
sql.executeUpdate(insert1);
show.setText("你插入了:");
show.append("学号:" + number + " 姓名:" + name + " 出生:" + date
+ " 数学 " + math + " 英语 " + english);
show.append("\n");
} catch (SQLException e) {
System.out.println(e);
JOptionPane.showMessageDialog(this, "你输入的学号已存在,请核对重新输入!");
}
}
}
/*
* 查询数据界面
*/
classchaxunextends JFrame implements ActionListener {
JFrame frame = new JFrame("查询记录");
JPanel imagePanel;
ImageIcon bg;
Button xunzhao;
TextField input;
TextArea show;
Box box;
String s;
Connection con;
Statement sql;
ResultSet rs;
chaxun() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
xunzhao = new Button("查找");
input = new TextField(10);
show = new TextArea(6, 43);
xunzhao.addActionListener(this);
show.setEditable(false);
box = Box.createHorizontalBox();
Label l1=new Label("输入学号");
l1.setFont(new Font("宋体",Font.BOLD,15));
l1.setForeground(Color.blue);
box.add(l1);
box.add(Box.createHorizontalStrut(8));
box.add(input);
box.add(Box.createHorizontalStrut(8));
box.add(xunzhao);
bg = new ImageIcon("4.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(box, BorderLayout.NORTH);
imagePanel.add(show, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(730, 230, 520, 350);
frame.setResizable(false);//设置窗口大小不可改变
frame.setVisible(true);
validate();
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
}
publicvoid actionPerformed(ActionEvent ee) {
boolean boo = true;
s = input.getText();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException eee) {
System.out.println("" + eee);
}
try {
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=学生成绩管理系统", "sa", "55151777");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM chengjibiao ");
while (rs.next()) {
String number = rs.getString("number");
String name = rs.getString("name");
String date = rs.getString("date");
int math = rs.getInt("math");
int english = rs.getInt("english");
if (number.equals(s)) {
boo = false;
show.setText(null);
show.append("学号:" + number + " 姓名:" + name + " 出生:"
+ date + " 数学 " + math + " 英语 " + english);
show.append("\n");
}
}
con.close();
if (boo) {
JOptionPane.showMessageDialog(this, "你输入的学号不存在");
}
} catch (SQLException eee) {
System.out.println(eee);
}
}
}
/*
* 删除记录界面
*/
classshanchuextends JFrame implements ActionListener {
JFrame frame = new JFrame("删除记录");
JPanel imagePanel;
ImageIcon bg;
Button xunzhao;
TextField input;
TextArea show;
String s;
int k, s1, j;
Connection con;
Statement sql;
int sum = 0;
ResultSet rs;
shanchu() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
Panel p = new Panel();
xunzhao = new Button("删除");
input = new TextField(15);
show = new TextArea(6, 43);
Label l1=new Label("输入要删除学生的学号");
l1.setFont(new Font("宋体",Font.BOLD,15));
l1.setForeground(Color.BLUE);
p.add(l1);
p.add(input);
p.add(xunzhao);
xunzhao.addActionListener(this);
show.setEditable(false);
bg = new ImageIcon("5.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p, BorderLayout.NORTH);
imagePanel.add(show, BorderLayout.CENTER);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(710, 210, 480, 310);
frame.setVisible(true);
frame.setResizable(false);//设置窗口大小不可改变
validate();
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
}
publicvoid actionPerformed(ActionEvent ee) {
boolean boo = true;
s = input.getText();
String m;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException eee) {
System.out.println("" + eee);
}
try {
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=学生成绩管理系统", "sa", "55151777");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM chengjibiao");
while (rs.next()) {
String number = rs.getString("number");
String name = rs.getString("name");
String date = rs.getString("date");
int math = rs.getInt("math");
int english = rs.getInt("english");
if (number.equals(s)) {
show.setText("你删除了:");
show.append("学号:" + number + " 姓名:" + name + " 出生:"
+ date + " 数学 " + math + " 英语 " + english);
show.append("\n");
m = "DELETE FROM chengjibiao WHERE number = '"
+ input.getText() + "'";
sql.executeUpdate(m);
}
}
con.close();
if (boo) {
JOptionPane.showMessageDialog(this, "你输入的学号不存在");
}
} catch (SQLException e) {
System.out.println(e);
}
}
}
/*
* 修改成绩界面
*/
classxiugaiextends JFrame implements ActionListener {
JFrame frame = new JFrame("修改成绩");
JPanel imagePanel;
ImageIcon bg;
Button xiug;
TextField input1, input2, input3;
TextArea show;
Box box1, box2, box3;
Panel p1, p2;
int k, s1, j;
Connection con;
Statement sql;
int sum = 0;
ResultSet rs;
xiugai() {
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.getImage("tubiao.jpg");
frame.setIconImage(img);
p1 = new Panel();
p2 = new Panel();
xiug = new Button("修改");
input1 = new TextField(10);
input2 = new TextField(10);
input3 = new TextField(10);
show = new TextArea(6, 43);
Font f=new Font("宋体",Font.BOLD,15);
Label l1=new Label("输入学号");
l1.setFont(f);
l1.setForeground(Color.blue);
p1.add(l1);
p1.add(new Label("学号:"));
p1.add(input1);
box1 = Box.createVerticalBox();
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("数学:"));
box1.add(Box.createVerticalStrut(8));
box1.add(new Label("英语:"));
box2 = Box.createVerticalBox();
box2.add(input2);
box2.add(Box.createVerticalStrut(8));
box2.add(input3);
box3 = Box.createHorizontalBox();
box3.add(box1);
box3.add(Box.createHorizontalStrut(1));
box3.add(box2);
Label l2=new Label("输入成绩");
l2.setFont(f);
l2.setForeground(Color.blue);
p2.add(l2);
p2.add(box3);
xiug.addActionListener(this);
show.setEditable(false);
bg = new ImageIcon("6.jpg");
JLabel label = new JLabel(bg);
label.setBounds(0, 0, bg.getIconWidth(), bg.getIconHeight());
imagePanel = (JPanel) frame.getContentPane();
imagePanel.setOpaque(false);
imagePanel.setLayout(new FlowLayout());
imagePanel.add(p1);
imagePanel.add(p2);
imagePanel.add(xiug);
imagePanel.add(show);
frame.getLayeredPane().setLayout(null);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(bg.getIconWidth(), bg.getIconHeight());
frame.setBounds(720, 220, 450, 390);
frame.setResizable(false);//设置窗口大小不可改变
frame.setVisible(true);
validate();
addWindowListener(new WindowAdapter() {
publicvoid windowClosing(WindowEvent e) {
dispose();
}
});
}
publicvoid actionPerformed(ActionEvent ee) {
String s1, s2, s3, insert1, number;
;
int m2, m3, math, english;
s1 = input1.getText();
number = s1;
s2 = input2.getText();
s3 = input3.getText();
m2 = Integer.parseInt(s2);
math = m2;
m3 = Integer.parseInt(s3);
english = m3;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException eee) {
System.out.println("" + eee);
}
try {
con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=学生成绩管理系统", "sa", "55151777");
sql = con.createStatement();
insert1 = "UPDATE chengjibiao SET math =" + math + ",english="
+ english + " WHERE number = " + "'" + number + "'";
sql.executeUpdate(insert1);
show.setText("你将了:");
show.append("学号为 " + s1 + " 的学生 数学成绩更改为:" + math + " 英语成绩更改为:"
+ english);
show.append("\n");
} catch (SQLException e) {
System.out.println(e);
}
}
}
指导老师批阅:
(封底)