系统分为三个身份,学生,教师,管理员。
每个身份对应不同的功能,管理员主要负责于基本的数据维护,多种的管理,增删改查。教师主要是对试题内容的修改,以及发布考试,选择考试题型,规定考试试题,也可以对学生分数进行查询,学生主要是进行教师发布过的考题进行考试。
教师输入完成账户和密码后点击登录。
btn1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
String username = text.getText();
String pwd=password.getText();
String shenfen= (String) box1.getSelectedItem();
//提醒用户账号密码不能为空
if (username.trim().length()==0){
JOptionPane.showMessageDialog(null, "账号不能为空");
return;
}
if (pwd.trim().length()==0){
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
BaseDao base=new BaseDao();
String sql="select * from user where username=? and password=? and shenfen=?";
ResultSet set=base.query(sql, username, pwd, shenfen);
//如果set为空,则返回
if (set==null) {
return;
}
try {
//管理员登录,判断管理员账号密码是否正确
if (shenfen.trim().equals("管理员")||username.equals("123456gl")||pwd.equals("123")) {
String words="登录成功";
playSound(words);
//JOptionPane.showMessageDialog(null, "登陆成功");
dispose();
Choose x=new Choose();
x.setVisible(true);
x.inte1();
return;
}
//判断数据库里是否有登录信息
else if (set.next()) {
//教师登录
if (shenfen.trim().equals("教师")) {
String words="登录成功";
playSound(words);
//JOptionPane.showMessageDialog(null, "登陆成功");
dispose();
choose2 z=new choose2();
z.inte1();
z.setVisible(true);
return;
}
//学生登录
else if (shenfen.trim().equals("学生")) {
String words="登录成功";
playSound(words);
//JOptionPane.showMessageDialog(null, "登陆成功");
dispose();
xh l=new xh();
l.setVisible(true);
}
}else
JOptionPane.showMessageDialog(null, "身份,账号或密码错误");
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}`
系统判断账户密码与数据库是否匹配,匹配登录后会有语音播报提示登录成功
在登陆成功后会进入到教师操作界面
教师功能主要有三大模块,考试的试题管理,发布在线考试,查询统计学生分数。
同时上边会有小菜单帮助教师的使用,可以注销账户,退出系统,功能帮助
//退出系统事件
jmf3.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(e.getStateChange()==ItemEvent.SELECTED){
//确定用户是否注销
int anwers=JOptionPane.showConfirmDialog(null, "您确定要退出吗", "是否退出", JOptionPane.OK_CANCEL_OPTION);
if (!(anwers==JOptionPane.OK_OPTION)) {
return;
}else{
System.exit(0);
}
}
}
});
//注销返回登陆界面
jmf2.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(e.getStateChange()==ItemEvent.SELECTED){
//确定用户是否注销
int anwers=JOptionPane.showConfirmDialog(null, "您确定要注销吗", "是否注销", JOptionPane.OK_CANCEL_OPTION);
if (!(anwers==JOptionPane.OK_OPTION)) {
return;
}else {
dispose();
Login l=new Login();
l.setVisible(true);
l.inte();
}
}
}
});
//跳转修改密码
j1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
dispose();//关闭当前
//打开修改界面
Xiugai l=new Xiugai();
l.setVisible(true);
l.inte();
}
});
试题管理功能主要是对试题的增删改查操作,对数据库中试题数据进行增删改的操作
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int row = jTable1.getSelectedRow();
//判断有没有选中表格中要修改的行
if (row == -1) {
JOptionPane.showMessageDialog(null, "请先选中一行!");
} else {
//2.获取表格被选中的行的各列的值,从表格某列获取的值是Object类型,要强转
int a1 = (Integer) jTable1.getValueAt(row, 0);
String a2 = (String) jTable1.getValueAt(row, 1);
String a3 = (String) jTable1.getValueAt(row, 2);
String a4 = (String) jTable1.getValueAt(row, 3);
String a5 = (String) jTable1.getValueAt(row, 4);
String a6 = (String) jTable1.getValueAt(row, 5);
String a7 = (String) jTable1.getValueAt(row, 6);
//3.打开修改窗体,并将选中的这一样要修改的数据传递到新的窗口
this.setVisible(false);
Xiugai x = new Xiugai(a1, a2, a3, a4, a5, a6, a7);
x.setVisible(true);
x.setTitle("修改试题");
x.setLocationRelativeTo(null);
x.setResizable(false);
}
}
//删除表数据
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
throws SQLException {
int row = jTable1.getSelectedRow();
int col = jTable1.getSelectedColumn();
if (row != -1) {
Object name = jTable1.getValueAt(row, 0);
String sql = "delete from photoshop where id=?";
BaseDao base = new BaseDao();
boolean result = base.update(sql, name);
int answer = JOptionPane.showConfirmDialog(null, "确认要删除吗?", "删除确认",
JOptionPane.OK_CANCEL_OPTION);
if (!(JOptionPane.OK_OPTION == answer))
return;
if (result) {
JOptionPane.showMessageDialog(null, "删除成功!");
init();
} else
JOptionPane.showMessageDialog(null, "删除失败!");
} else {
JOptionPane.showMessageDialog(null, "请先选中要删除的行");
}
}
//跳转到增加数据界面
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
new add().setVisible(true);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
shujuweihu shu = new shujuweihu();
shu.initComponents();
shu.setVisible(true);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
throws SQLException {
List<Shiti> list = new ArrayList<Shiti>();
String[] title = { "试题编号", "试题", "答案A", "答案B", "答案C", "答案D", "正确答案" };
String sql = "select * from photoshop";
String tName = null;
String huoqu = (String) jComboBox1.getSelectedItem();
if (huoqu.equals("试题编号")) {
sql = "select * from photoshop where id=?";
tName = jTextField1.getText();
}
if (huoqu.equals("试题")) {
sql = "select * from photoshop where name like ?";
tName = "%" + jTextField1.getText() + "%";
}
if (huoqu.equals("正确答案")) {
sql = "select * from photoshop where right1 like ?";
tName = jTextField1.getText()+"%";
}
BaseDao base = new BaseDao();
ResultSet set = base.query(sql, tName);
while (set.next()) {
int id = set.getInt(1);
String name = set.getString(2);
String a = set.getString(3);
String b = set.getString(4);
String c = set.getString(5);
String d = set.getString(6);
String right = set.getString(7);
Shiti ta = new Shiti(id, name, a, b, c, d, right);
list.add(ta);
}
Object[][] data = new Object[list.size()][7];
for (int i = 0; i < list.size(); i++) {
data[i][0] = list.get(i).getId();
data[i][1] = list.get(i).getName();
data[i][2] = list.get(i).getA();
data[i][3] = list.get(i).getB();
data[i][4] = list.get(i).getC();
data[i][5] = list.get(i).getD();
data[i][6] = list.get(i).getRight();
}
DefaultTableModel dtm = new DefaultTableModel(data, title);
jTable1.setModel(dtm);
}
public void init() throws SQLException {
List<Shiti> list = new ArrayList<Shiti>();
String[] title = { "试题编号", "试题", "答案A", "答案B", "答案C", "答案D", "正确答案" };
String sql = "select * from photoshop";
BaseDao base = new BaseDao();
ResultSet set = base.query(sql);
while (set.next()) {
int id = set.getInt(1);
String name = set.getString(2);
String a = set.getString(3);
String b = set.getString(4);
String c = set.getString(5);
String d = set.getString(6);
String right = set.getString(7);
Shiti ta = new Shiti(id, name, a, b, c, d, right);
list.add(ta);
}
Object[][] data = new Object[list.size()][7];
for (int i = 0; i < list.size(); i++) {
data[i][0] = list.get(i).getId();
data[i][1] = list.get(i).getName();
data[i][2] = list.get(i).getA();
data[i][3] = list.get(i).getB();
data[i][4] = list.get(i).getC();
data[i][5] = list.get(i).getD();
data[i][6] = list.get(i).getRight();
}
DefaultTableModel dtm = new DefaultTableModel(data, title);
jTable1.setModel(dtm);
}
发布考试功能主要是教师可以自主的选择考试的试题内容,在选择完试题后进行发布考试,并规定考试的时间,将考试发布到学生端。
先选择要发布的考试类型
jButton1.setText("Mysql基础知识");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("计算机基础");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("H5\u9875\u9762\u8bbe\u8ba1");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("PS\u8fd0\u7528");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
比如选择PS运用
在这里面可以选择随机组卷这样自动生成一份PS的考试试卷,
也可以选择试题再发布考试。
String sql="update kaoshijian set time=?";
int time=Integer.parseInt(jTextField1.getText());
BaseDao base=new BaseDao();
boolean result=base.update(sql, time);
this.setVisible(false);
new susecc().setVisible(true);
在成绩查询统计模块,教师可以对成绩进行查询,也有倒叙跟正序的查询,同时也提供了将成绩导出到Excil表格里。
//将数据库的数据导出到Excel
public class excel {
// 导出的Excel表的sheet名字设置为:学生的信息
public static String tables = "学生的成绩";
// sql语句 选择导出数据库的哪个表
public static String sqls = "select * from student2";
// 导出表的csv文件保存的地址
public static String outputFile = "E://学生成绩表.xls";
public static Connection con = null;
//创建Excel文件(Workbook)
HSSFWorkbook workbook = new HSSFWorkbook();
String[] tempo;
int rowNum = 1;
try {
//执行数据库的sq语句
ps_struts = con.prepareStatement(sqls);
rs_struts = ps_struts.executeQuery();
//获取Connection对象所连接的数据库的元数据。元数据包括关于数据库的表
ResultSetMetaData rsm = rs_struts.getMetaData();
//创建一个名字为(tables)的表原名字默认为sheet
HSSFSheet sheet = workbook.createSheet(tables);
//getRowCount 获取数据库表行的数量 getColumnCount获取列的数量
int columnCount = rsm.getColumnCount();
//把表头填好
try {
//在Excel里创建行,从0开始
HSSFRow row1 = sheet.createRow(0);
for (int i = 1;i<=columnCount;i++) {
//让Excel自动适应列宽
sheet.autoSizeColumn(i);
//获取表列头的名字
String columnName = rsm.getColumnName(i);
//创建行的单元格,也是从0开始
HSSFCell cell1 = row1.createCell(i - 1);
//设置单元格内容
cell1.setCellValue(columnName);
}
} catch (Exception e) {
e.printStackTrace();
}
//循环数据库表中的每一行,来得到每一行的数据
while (rs_struts.next()) {
//每循环一次创建一行从 1 开始
HSSFRow row = sheet.createRow(rowNum);
tempo = new String[columnCount];
for (int i = 0; i < columnCount; i++) {
//创建行的单元格,从0开始
HSSFCell cell = row.createCell(i);
//让Excel自动适应列宽
sheet.autoSizeColumn(i);
//getMetaData().getColumnName(i);字段名
String columnName = rs_struts.getMetaData().getColumnName(i + 1);
tempo[i] = rs_struts.getString(columnName);
//设置单元格内容
cell.setCellValue(tempo[i]);
}
//每次循环结束后要使数组为空,方便存储数据库表中下一行的数值
tempo = null;
//rowNum++ 下一次循环创建的行向下
rowNum++;
}
} catch (SQLException e1) {
e1.printStackTrace();
}
FileOutputStream fOut = new FileOutputStream(outputFile);
workbook.write(fOut);//保存Excel文件
链接:https://pan.baidu.com/s/1WMx2LDdlyNWVEf0DakDZug
提取码加qq:2365621464