基于java+mysql的swing+mysql考试系统java基础gui(java+gui)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java+mysql的Swing+MySQL考试系统java基础gui(java+gui)
功能简介:
所属课程、题目内容、题目选项、题目答案、题目等级、学生管理、试卷管理、题目管理、时间控制
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CreatePaper extends javax.swing.JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
// 注入TitleManage
private TitleManage titleManage = new TitleManageImp();
// 注入UserManage
public void windowClosing(WindowEvent e) {
int var = JOptionPane.showConfirmDialog(ExamClient.this,
"确定离开吗?");
if (var == JOptionPane.YES_OPTION) {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}
}
});
try {
pack();
this.setSize(812, 499);
} catch (Exception e) {
// add your error handling code here
e.printStackTrace();
}
// 设置居中和可见
setLocationRelativeTo(null);
setVisible(true);
// 固定大小
setResizable(false);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setLayout(null);
jPanel1.setPreferredSize(new java.awt.Dimension(716, 455));
jPanel1.add(getJScrollPane1());
{
jLabel1 = new JLabel();
jPanel1.add(jLabel1);
jLabel1.setBounds(77, 7, 420, 35);
jLabel1.setFont(new java.awt.Font("楷体", 0, 20));
}
{
jButton1 = new JButton();
jPanel1.add(jButton1);
jButton1.setText("开始做题");
jButton1.setBounds(165, 399, 99, 23);
}
{
jButton2 = new JButton();
jPanel1.add(jButton2);
jButton2.setText("下一题");
jButton2.setBounds(472, 399, 81, 23);
}
{
jButton3 = new JButton();
jPanel1.add(jButton3);
jButton3.setText("提交");
jButton3.setBounds(622, 399, 81, 23);
}
{
jCheckBox1 = new Checkbox("A", checkboxGroup, true);
jPanel1.add(jCheckBox1);
jButton1.setBounds(396, 386, 83, 28);
}
{
jButton3 = new JButton();
jPanel1.add(jButton3);
jButton3.setText("修改");
jButton3.setBounds(235, 386, 83, 28);
}
{
jButton4 = new JButton();
jPanel1.add(jButton4);
jButton4.setText("\u5237\u65b0");
jButton4.setBounds(559, 386, 83, 28);
}
{
jButton2 = new JButton();
jPanel1.add(jButton2);
jButton2.setText("\u5bfc\u5165\u5b66\u751f");
jButton2.setBounds(79, 386, 86, 28);
}
}
pack();
this.setSize(715, 468);
setLocationRelativeTo(null);
setVisible(true);
// 导入学生的事件
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ImportUser iu = new ImportUser();
try {
userManage.setAuto_increment(1001);
iu.insertUser(iu.getStudents());
listTitle = titleList();
TableModel jTable1Model = new DefaultTableModel(
listTitle, new String[] { "学生编号", "学生姓名",
"学生密码", "试卷编号" });
jTable1.setModel(jTable1Model);
jButton2.setEnabled(false);
}
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class UpdateTitleFrame extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
/**
* Auto-generated main method to display this JFrame
*/
private JButton jButton1;
private JLabel jLabel2;
private JLabel jLabel3;
private JComboBox jComboBox1;
private JComboBox jComboBox5;
private JComboBox jComboBox4;
private JComboBox jComboBox3;
private JLabel jLabel1;
private JTextArea jTextArea1;
private JTextField jTextField2;
private JButton jButton2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}
/**
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
* Builder, which is free for non-commercial use. If Jigloo is being used
* commercially (ie, by a corporation, company or business for any purpose
* whatever) then you should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details. Use of Jigloo implies
* acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
* PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
* ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AddTitleFrame extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
/**
// int title3[] = new int[1];
// int n3 = 0;
// int title4[] = new int[1];
// int n4 = 0;
// int title5[] = new int[1];
// int n5 = 0;
// int title6[] = new int[1];
// int n6 = 0;
// int title7[] = new int[1];
// int n7 = 0;
// int title8[] = new int[1];
// int n8 = 0;
// int title9[] = new int[1];
// int n9 = 0;
// int title10[] = new int[1];
// int n10 = 0;
Title title = null;
for (int i = 0; i < listTitles.size(); i++) {
title = listTitles.get(i);
if (title.getLevel() == 1) {
title1[n1] = title.getTid();
n1++;
// 数组扩容
int length = title1.length;
title1 = Arrays.copyOf(title1, length + 1);
}
if (title.getLevel() == 2) {
title2[n2++] = title.getTid();
int length = title2.length;
title2 = Arrays.copyOf(title2, length + 1);
}
// if (title.getLevel() == 3) {
// title3[n3++] = title.getTid();
// int length = title3.length;
// title3 = Arrays.copyOf(title3, length + 1);
// }
//
// if (title.getLevel() == 4) {
// title4[n4++] = title.getTid();
// int length = title4.length;
// title4 = Arrays.copyOf(title4, length + 1);
// }
//
// if (title.getLevel() == 5) {
// title5[n5++] = title.getTid();
// int length = title5.length;
// title5 = Arrays.copyOf(title5, length + 1);
// }
// if (title.getLevel() == 6) {
// title6[n6++] = title.getTid();
// int length = title6.length;
// title6 = Arrays.copyOf(title6, length + 1);
private JLabel jLabel1;
private JLabel jLabel10;
private JLabel jLabel11;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel12;
private JComboBox jComboBox3;
private JComboBox jComboBox2;
private JComboBox jComboBox1;
private JTextField jTextField3;
private JLabel jLabel6;
private JLabel jLabel7;
private JLabel jLabel8;
private JLabel jLabel9;
private JPanel jPanel1;
private JTextArea jTextArea1;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField4;
private JComboBox jComboBox4;
/**
*
*/
// 注入Service
private TitleManage titleManage = new TitleManageImp();
public AddTitleFrame() {
super();
initGUI();
}
public JTextField getJTextField2() {
return jTextField2;
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1);
jPanel1.setBounds(0, 0, 723, 488);
e.printStackTrace();
}
}
/**
* Auto-generated main method to display this JFrame
*/
public static String[][] titleList() {
List<Title> listTitle = titleManage.findAll();
int size = listTitle.size();
String titleStr[][] = new String[size][7];
for (int i = 0; i < listTitle.size(); i++) {
Title title = listTitle.get(i);
titleStr[i][0] = title.getTid() + "";
titleStr[i][1] = title.getCourse();
titleStr[i][2] = title.getQuestion();
titleStr[i][3] = title.getOption();
titleStr[i][4] = title.getKey();
titleStr[i][5] = title.getLevel() + "";
titleStr[i][6] = title.getScore() + "";
}
return titleStr;
}
public TitleManageFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.setLayout(null);
{
jScrollPane1 = new JScrollPane();
// break;
// }
// listTitle = index3_1 + "," + index3_2;
// // System.out.println(listTitle);
// // 等级为4
// int index4_1 = rd.nextInt(n4);
// int index4_2 = 0;
// while (true) {
// if(n4<=1) {
// break;
// }
// index4_2 = rd.nextInt(n4);
// if (index4_1 != index4_2)
// break;
// }
// listTitle = index4_1 + "," + index4_2;
// // System.out.println(listTitle);
// // 等级为5
// int index5_1 = rd.nextInt(n5);
// int index5_2 = 0;
// while (true) {
// if(n5<=1) {
// break;
// }
// index5_2 = rd.nextInt(n5);
// if (index5_1 != index5_2)
// break;
// }
// // 等级为6
// int index6_1 = rd.nextInt(n6);
// int index6_2 = 0;
// while (true) {
// if(n6<=1) {
// break;
// }
// index6_2 = rd.nextInt(n6);
// if (index6_1 != index6_2)
// break;
// }
// // 等级为7
// int index7_1 = rd.nextInt(n7);
// int index7_2 = 0;
// while (true) {
// if(n7<=1) {
// break;
// }
// index7_2 = rd.nextInt(n7);
// if (index7_1 != index7_2)
// break;
// }
// }
// // 等级为10
// int index10_1 = rd.nextInt(n10);
// int index10_2 = 0;
// while (true) {
// if(n10<=1) {
// break;
// }
// index10_2 = rd.nextInt(n10);
// if (index10_1 != index10_2)
// break;
// }
/*
* System.out.println(index1_1 + "," + index1_2 + "," + index2_1 + "," +
* index2_2 + "," + index3_1 + "," + index3_2 + "," + index4_1 + "," +
* index4_2 + "," + index5_1 + "," + index5_2);
*/
listTitle = title1[index1_1] + "," + title1[index1_2] + ","
+ title2[index2_1] + "," + title2[index2_2];
//
// + title3[index3_1] + "," + title3[index3_2] + ","
// + title4[index4_1] + "," + title4[index4_2] + ","
// + title5[index5_1] + "," + title5[index5_2] + ","
// + title6[index6_1] + "," + title6[index6_2] + ","
// + title7[index7_1] + "," + title7[index7_2] + ","
// + title8[index8_1] + "," + title8[index8_2] + ","
// + title9[index9_1] + "," + title9[index9_2] + ","
// + title10[index10_1] + "," + title10[index10_2];
System.out.println(listTitle);
/*
* System.out.println(Arrays.toString(title1));
* System.out.println(Arrays.toString(title2));
* System.out.println(Arrays.toString(title3));
* System.out.println(Arrays.toString(title4));
* System.out.println(Arrays.toString(title5));
*/
// System.out.println(listTitle);
return listTitle;
}
}
jButton2.setBounds(365, 402, 68, 24);
}
{
jTextField4 = new JTextField();
jPanel1.add(jTextField4);
jTextField4.setBounds(436, 177, 131, 21);
}
{
jLabel8 = new JLabel();
jPanel1.add(jLabel8);
jLabel8.setText("\u9898\u76ee\u96be\u5ea6");
jLabel8.setBounds(67, 274, 68, 17);
}
{
jLabel9 = new JLabel();
jPanel1.add(jLabel9);
jLabel9.setText("1---5\u4e4b\u95f4");
jLabel9.setBounds(267, 277, 137, 17);
}
{
jLabel10 = new JLabel();
jPanel1.add(jLabel10);
jLabel10.setText("\u9898\u76ee\u5206\u6570");
jLabel10.setBounds(67, 327, 68, 17);
jLabel10.setOpaque(true);
}
{
jLabel11 = new JLabel();
jPanel1.add(jLabel11);
jLabel11.setText("0---100\u4e4b\u95f4");
jLabel11.setBounds(267, 327, 137, 17);
jLabel11.setOpaque(true);
}
{
jTextField3 = new JTextField();
jPanel1.add(jTextField3);
jTextField3.setBounds(195, 176, 131, 24);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
jComboBox1 = new JComboBox();
+ jTextField4.getText();
String key = (String) jComboBox2.getSelectedItem();
int level = (Integer) (jComboBox1.getSelectedItem());
int score = (Integer) jComboBox3.getSelectedItem();
String course = (String) jComboBox4.getSelectedItem();
System.out.println(level);
Title title = new Title();
// title.setTid(1);
title.setQuestion(question);
title.setOption(option);
title.setKey(key);
title.setLevel(level);
title.setScore(score);
title.setCourse(course);
titleManage.save(title);
JOptionPane.showMessageDialog(AddTitleFrame.this, "add success!!!");
}
});
} catch (Exception e) {
// add your error handling code here
e.printStackTrace();
}
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextArea1.setText("");
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jComboBox1.setSelectedIndex(0);
jComboBox2.setSelectedIndex(2);
jComboBox3.setSelectedIndex(4);
}
});
}
}
jButton2 = new JButton();
jPanel1.add(jButton2);
jButton2.setText("\u624b\u52a8\u589e\u52a0");
jButton2.setBounds(190, 391, 89, 28);
}
{
jButton3 = new JButton();
jPanel1.add(jButton3);
jButton3.setText("修改");
jButton3.setBounds(342, 391, 77, 28);
}
{
jButton4 = new JButton();
jPanel1.add(jButton4);
jButton4.setText("\u5237\u65b0");
jButton4.setBounds(609, 391, 74, 28);
}
{
jButton5 = new JButton();
jPanel1.add(jButton5);
jButton5.setText("\u6279\u91cf\u5bfc\u5165");
jButton5.setBounds(54, 391, 86, 28);
}
}
pack();
this.setSize(715, 468);
setLocationRelativeTo(null);
setVisible(true);
// 批量导入的事件
jButton5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ImportTitle iu = new ImportTitle();
try {
titleManage.setAuto_increment(1);
iu.insertTitle(iu.getTitles());
listTitle = titleList();
jLabel8.setText("\u9898\u76ee\u96be\u5ea6");
jLabel8.setBounds(67, 274, 68, 17);
}
{
jLabel9 = new JLabel();
jPanel1.add(jLabel9);
jLabel9.setText("1---5\u4e4b\u95f4");
jLabel9.setBounds(267, 277, 137, 17);
}
{
jLabel10 = new JLabel();
jPanel1.add(jLabel10);
jLabel10.setText("\u9898\u76ee\u5206\u6570");
jLabel10.setBounds(67, 327, 68, 17);
jLabel10.setOpaque(true);
}
{
jLabel11 = new JLabel();
jPanel1.add(jLabel11);
jLabel11.setText("0---100\u4e4b\u95f4");
jLabel11.setBounds(267, 327, 137, 17);
jLabel11.setOpaque(true);
}
{
jTextField3 = new JTextField();
jPanel1.add(jTextField3);
jTextField3.setBounds(195, 176, 131, 24);
}
{
ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(
new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
jComboBox1 = new JComboBox();
jPanel1.add(jComboBox1);
jComboBox1.setModel(jComboBox1Model);
jComboBox1.setBounds(176, 270, 73, 24);
}
{
ComboBoxModel jComboBox2Model = new DefaultComboBoxModel(
new String[] { "A", "B", "C", "D" });
jComboBox2 = new JComboBox();
jPanel1.add(jComboBox2);
jComboBox2.setModel(jComboBox2Model);
jComboBox2.setBounds(176, 225, 73, 24);
// GEN-END:initComponents
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginFrame().setVisible(true);
}
});
}
// 得到输入量 匹配用户名和密码
public static String getNameAndPassword(String str, String str1)
throws IOException {
InputStreamReader is = new InputStreamReader(new FileInputStream(
new File("user.txt")));
BufferedReader br = new BufferedReader(is);
String line;
while (null != (line = br.readLine())) {
String[] np = line.split(":");
if (str.equals(np[0]) && str1.equals(np[2])) {
return np[1];
}
}
is.close();
return null;
}
// GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private JPasswordField jPasswordField1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
th.stop();
jLabel3.setText("考试结束");
}
});
}
private JTextArea getJTextArea1() {
if (jTextArea1 == null) {
jTextArea1 = new JTextArea();
jTextArea1.setBounds(68, 50, 660, 285);
}
return jTextArea1;
}
private JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new JScrollPane();
jScrollPane1.setBounds(68, 50, 660, 285);
jScrollPane1.setViewportView(getJTextArea1());
}
return jScrollPane1;
}
private Checkbox getJCheckBox4() {
if (jCheckBox4 == null) {
jCheckBox4 = new Checkbox("D", checkboxGroup, false);
// jCheckBox4.setText("D");
jCheckBox4.setBounds(516, 359, 44, 22);
}
return jCheckBox4;
}
private JButton getJButton5() {
if (jButton5 == null) {
jButton5 = new JButton();
jButton5.setText("\u4e0a\u4e00\u9898");
jButton5.setBounds(338, 399, 81, 23);
}
return jButton5;
}
// 显示题目状态
{
jLabel10 = new JLabel();
jPanel1.add(jLabel10);
jLabel10.setText("\u8bd5\u5377\u7f16\u53f7");
jLabel10.setBounds(135, 307, 68, 17);
jLabel10.setOpaque(true);
}
{
jLabel2 = new JLabel();
jPanel1.add(jLabel2);
jLabel2.setText("\u5b66\u751f\u7f16\u53f7");
jLabel2.setBounds(135, 123, 91, 33);
}
{
jTextField1 = new JTextField();
jPanel1.add(jTextField1);
jTextField1.setText(user.getUid() + "");
jTextField1.setEditable(false);
jTextField1.setBounds(238, 128, 181, 24);
}
{
jTextField2 = new JTextField();
jPanel1.add(jTextField2);
jTextField2.setText(user.getName());
jTextField2.setEditable(false);
jTextField2.setBounds(238, 192, 181, 24);
}
{
jTextField3 = new JTextField();
jPanel1.add(jTextField3);
jTextField3.setText(user.getPassword());
jTextField3.setBounds(238, 250, 181, 23);
}
{
jTextField4 = new JTextField();
jPanel1.add(jTextField4);
jTextField4.setText(paper + "");
jTextField4.setEditable(false);
jTextField4.setBounds(238, 304, 181, 23);
}
}
pack();
this.setSize(552, 391);
setLocationRelativeTo(null);
setVisible(true);
jTextField1.setEditable(false);
@Override
public void run() {
try {
b = timeDown(paperManage.findById(uid).getTime());
if (b == false) {
mapAnswer
.put(i, checkboxGroup.getSelectedCheckbox().getLabel());
for (int i = 1; i <= mapAnswer.size(); i++) {
//保存最后一题答案
int tid2 = Integer
.parseInt(strTitle[i - 1]);
// 取题目
Title tit = titleManage.findById(tid2);
String key = tit.getKey();
// System.out.println(mapAnswer.get(i) +
// " " + key);
if (key.equals(mapAnswer.get(i))) {
// System.out.println(tit.getScore());
userPoint = userPoint + tit.getScore();
}
}
JOptionPane.showMessageDialog(ExamClient.this,
"时间到 " + username + "你的得分是:"
+ userPoint);
// 设置 除提交按钮外 所有按钮为不可用
jButton2.setEnabled(false);
jButton3.setEnabled(false);
jButton5.setEnabled(false);
}
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
// 判断时间是不是完成
boolean b = true;