单项选择题标准化考试系统
项目功能模块
系统功能模块如下:
1.学生账号登陆和注册
2. 通过增删改查组成题库,输入题目数量,然后从题库中抽取题目来答题,根据答题的选择和标准答案对比,自动评分。
3.可以查询历史记录,以及上机下机的时间。
package 单项选择题考试系统;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Vector;
import java.awt.event.ActionEvent;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
public class changeT extends JFrame {
private JPanel contentPane;
private JTextField textField;
private JTextField textFieldC;
private JTextField textFieldB;
private JTextField textFieldA;
private JTextField textFieldD;
private JTextField ans;
JTextArea textArea;
int p=0;
int topicnum=0;
Testquestion[] questions;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
changeT frame = new changeT();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public void createExam() {//创建考试模块
Vector<Testquestion> qList=null;//创建一个向量列表,用于动态增加试题
Testquestion t;
String questionText="";
String questionTexta="";
String questionTextb="";
String questionTextc="";
String questionTextd="";
String standardKey;
String s="";
try {
// FileReader fr=new FileReader("a.txt");
File file = new File("a.txt");
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis,"UTF-8");
BufferedReader br = new BufferedReader(isr); //可以每次读一行
qList=new Vector<Testquestion>();
int x=0;
while((s=br.readLine())!=null){//读取试题
questionText=s;//准备接收一个题目的内容
s = br.readLine();//获取试题内容的首行
questionTexta=s;
s = br.readLine();
questionTextb=s;
s = br.readLine();
questionTextc=s;
s = br.readLine();
questionTextd=s;
s = br.readLine(); //获取试题的答案
standardKey = s; //把试题答案赋值给正确答案
t = new Testquestion(questionText,questionTexta,questionTextb,questionTextc,questionTextd,standardKey); //把试题和答案赋值给t
qList.add(t); //把试题和答案赋值给列表
}
br.close();//关闭缓冲流
fis.close();//关闭文件流
}
catch (IOException e) {
e.printStackTrace(); //打印异常信息
}
topicnum=qList.size(); //统计试题数量
questions=new Testquestion[topicnum];
for (int i=0;i<qList.size();i++) //读取试题
questions[i]=qList.get(i);
}
public void showQuestion() {//设置试题模块
String ss=questions[p].getQuestionText();
ss+="\r\n";
ss+=questions[p].getQuestionTexta();
ss+="\r\n";
ss+=questions[p].getQuestionTextb();
ss+="\r\n";
ss+=questions[p].getQuestionTextc();
ss+="\r\n";
ss+=questions[p].getQuestionTextd();
ss+="\n";
textArea.append(ss);//在文本区域显示试题
}
public changeT() {
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.CENTER);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(0, 93, 426, 124);
panel.add(scrollPane);
textArea = new JTextArea();
scrollPane.setViewportView(textArea);
JButton btnNewButton = new JButton("\u4FEE\u6539");
btnNewButton.setBounds(0, 220, 97, 30);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String s="";
String qf=textField.getText();
boolean ff=false;
int x=0;
for (int i=0;i<topicnum;i++) {
if(questions[i].getQuestionText().equals(qf)){
x=i;
ff=true;
break;
}
}
if(!ff) {
JOptionPane.showMessageDialog(null, "题目不存在");
}
else {
try {
FileOutputStream fis=new FileOutputStream("a.txt");
OutputStreamWriter isw=new OutputStreamWriter(fis,"UTF-8");
BufferedWriter bw=new BufferedWriter(isw);
if(s.equals(textField.getText())) {
JOptionPane.showMessageDialog(null, "题目为空");
}
else {
questions[x].setQuestionText(textField.getText());
questions[x].setQuestionTexta(textFieldA.getText());
questions[x].setQuestionTextb(textFieldB.getText());
System.out.println(questions[x].getQuestionTextb());
questions[x].setQuestionTextc(textFieldC.getText());
questions[x].setQuestionTextd(textFieldD.getText());
questions[x].setStandardkey(ans.getText());
for(int i=0;i<topicnum;i++) {
if(i==x) {
String ss=questions[i].getQuestionText();
ss+="\r\n";
ss+="A."+questions[i].getQuestionTexta();
ss+="\r\n";
ss+="B."+questions[i].getQuestionTextb();
ss+="\r\n";
ss+="C."+questions[i].getQuestionTextc();
ss+="\r\n";
ss+="D."+questions[i].getQuestionTextd();
ss+="\n";
ss+=questions[i].getStandardkey();
ss+="\n";
bw.write(ss);
}
else {
String ss=questions[i].getQuestionText();
ss+="\r\n";
ss+=questions[i].getQuestionTexta();
ss+="\r\n";
ss+=questions[i].getQuestionTextb();
ss+="\r\n";
ss+=questions[i].getQuestionTextc();
ss+="\r\n";
ss+=questions[i].getQuestionTextd();
ss+="\n";
ss+=questions[i].getStandardkey();
ss+="\n";
bw.write(ss);
}
}
JOptionPane.showMessageDialog(null, "修改成功");
}
bw.close();
fis.close();
}
catch (IOException e1) {
e1.printStackTrace(); //打印异常信息
}
}
}
});
panel.setLayout(null);
panel.add(btnNewButton);
JLabel lblNewLabel = new JLabel("\u9898\u76EE");
lblNewLabel.setBounds(0, 10, 32, 15);
panel.add(lblNewLabel);
textField = new JTextField();
textField.setBounds(29, 7, 105, 21);
panel.add(textField);
textField.setColumns(10);
JLabel lblNewLabel_1 = new JLabel("A");
lblNewLabel_1.setBounds(144, 13, 21, 15);
panel.add(lblNewLabel_1);
textFieldC = new JTextField();
textFieldC.setBounds(171, 35, 93, 21);
panel.add(textFieldC);
textFieldC.setColumns(10);
JLabel lblNewLabel_2 = new JLabel("B");
lblNewLabel_2.setBounds(280, 10, 21, 15);
panel.add(lblNewLabel_2);
textFieldB = new JTextField();
textFieldB.setBounds(310, 7, 116, 21);
panel.add(textFieldB);
textFieldB.setColumns(10);
JLabel lblNewLabel_3 = new JLabel("C");
lblNewLabel_3.setBounds(143, 38, 21, 15);
panel.add(lblNewLabel_3);
JLabel lblNewLabel_4 = new JLabel("D");
lblNewLabel_4.setBounds(280, 35, 21, 18);
panel.add(lblNewLabel_4);
textFieldA = new JTextField();
textFieldA.setBounds(171, 10, 93, 21);
panel.add(textFieldA);
textFieldA.setColumns(10);
textFieldD = new JTextField();
textFieldD.setBounds(310, 35, 116, 21);
panel.add(textFieldD);
textFieldD.setColumns(10);
JLabel lblNewLabel_5 = new JLabel("\u7B54\u6848");
lblNewLabel_5.setBounds(0, 35, 32, 15);
panel.add(lblNewLabel_5);
ans = new JTextField();
ans.setBounds(29, 34, 103, 23);
panel.add(ans);
ans.setColumns(10);
JButton xs = new JButton("\u663E\u793A");
xs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.setText("");
createExam();
for(int i=0;i<topicnum;i++) {
p=i;
int x=i+1;
String s=x+".";
textArea.append(s);
showQuestion();
}
}
});
xs.setBounds(280, 220, 95, 30);
panel.add(xs);
JButton btnNewButton_1 = new JButton("\u586B\u5145");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createExam();
String ss=textField.getText();
int x=0;
boolean ff=false;
for(int i=0;i<topicnum;i++) {
if(ss.equals(questions[i].getQuestionText())) {
x=i;
ff=true;
break;
}
}
if(!ff) {
JOptionPane.showMessageDialog(null, "编号不存在");
}
else {
textField.setText(questions[x].getQuestionText());
textFieldA.setText(questions[x].getQuestionTexta().substring(2));
textFieldB.setText(questions[x].getQuestionTextb().substring(2));
textFieldC.setText(questions[x].getQuestionTextc().substring(2));
textFieldD.setText(questions[x].getQuestionTextd().substring(2));
ans.setText(questions[x].getStandardkey());
JOptionPane.showMessageDialog(null, "填充完成");
}
}
});
btnNewButton_1.setBounds(140, 220, 97, 30);
panel.add(btnNewButton_1);
}
}