📄 testingpanel.java
字号:
this.updateInfo();
}//GEN-LAST:event_submitActionPerformed
private void nextItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextItemActionPerformed
// TODO 将在此处添加您的处理代码:
this.sum += this.curItem.getScore();//放弃是肯定没分的!
this.showNextItem();
this.updateInfo();
}//GEN-LAST:event_nextItemActionPerformed
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JPanel ItemArea;
private javax.swing.JButton exit;
private javax.swing.JPanel infoArea;
private javax.swing.JLabel jLabel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JLabel labelForInfo;
private javax.swing.JButton nextItem;
private javax.swing.JPanel opArea;
private javax.swing.JButton submit;
private javax.swing.JTextField textFieldForItem;
private javax.swing.JTextField textFieldForResult;
private javax.swing.JTextField textFieldForTimer;
// 变量声明结束//GEN-END:variables
//这是自己加入的变量
private MainFrame mainFrame;
private int sum = 0;
private int score = 0;
private int count = 0;
private Item curItem;
private Timer itemClock;
private Timer itemWatch;
/**抽取下一题继续进行测试*/
public void showNextItem(){
try{
this.textFieldForItem.setText(" ");
this.textFieldForTimer.setText(" ");
this.curItem = this.mainFrame.getItemByCondition();
if (this.curItem != null){
this.mainFrame.setPickUpStatus(true);
this.count++;
this.textFieldForItem.setText("难度:"+this.curItem.getDifficulty()+
" 分值:"+this.curItem.getScore());
curItem.draw(this.ItemArea);
this.closeTimer();
if (curItem.getTimeLimit() != 0){
this.itemClock = new Timer(this.curItem.getTimeLimit()*1000,
new ItemClockListener());
this.itemClock.setRepeats(false);
this.itemClock.start();//启动倒计时器
this.itemWatch = new Timer(this.curItem.getTimeLimit()*100,
new ItemWatchListener());
this.itemWatch.start();
}
this.textFieldForResult.setText("您已经做了"
+ (this.count-1) + "题目,所得分/总分值=" + this.score+"/" + this.sum);
this.mainFrame.repaint();
this.mainFrame.pack();
}else {
if (this.count == 0){
this.mainFrame.setPickUpStatus(false);
this.mainFrame.reset();
//找不到题目的错误
}else {
this.complete();
}
}
}catch(Exception e){
JOptionPane.showMessageDialog
(this,e.toString());
this.mainFrame.reset();
}
}
/**
*做完题了就运行这个方法,显示成绩
*/
private void complete(){
this.closeTimer();
String result = "做完啦!总共做了" + this.count + "题,";
double mark = ((double)this.score) / ((double)this.sum) * 100;
result += "您的得分折合成百分制是:";
result += (int)mark;
JOptionPane.showMessageDialog(this, result);
this.mainFrame.reset();
}
/**
*计算分数
*/
private void countSum(){
this.sum = this.sum + this.curItem.getScore();
if (this.curItem.isCorrect() == true){
//只有正确答对了题目才有分数
this.score += this.curItem.getScore();
}
}
/**
* 刷新信息标签
*/
private void updateInfo(){
String info = "";
String condition = this.mainFrame.getConditionType();
if (condition.equals("random")){
info += "您选择的是随机测试";
}else {
if (condition.equals("all")){
info += "您选择的是测试全部试题,";
}else if(condition.equals("id")){
info += "您选择的是按ID取题,";
}else if (condition.equals("combination")){
info += "您选择的是利用组合查询的方式生成试卷,";
}
}
this.labelForInfo.setText(info);
}
/**
* 主面板调用这个方法开始测试的过程
*/
public void start(){
this.showNextItem();
this.updateInfo();
}
/**
*用于实现对做一道题是第时间限制
*/
class ItemClockListener implements ActionListener{
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(mainFrame, "时间到啦!将强制开始下一题");
sum += curItem.getScore();//放弃是肯定没分的!
showNextItem();
updateInfo();
}
}
/**
*用于在做题的时候进行倒计时
*/
class ItemWatchListener implements ActionListener{
private int count = 1;
public void actionPerformed(ActionEvent e){
//题目完成倒计时
textFieldForTimer.setText("离提交时间还有:" + (
curItem.getTimeLimit() - this.count ) + "秒");
this.count++;
if (this.count == 10){
textFieldForTimer.setText("时间到!");
itemWatch.stop();
}
}
}
public void closeTimer(){
if (this.itemClock != null){
this.itemClock.stop();//保证之前的计时器已经关闭!
}
if(this.itemWatch != null){
this.itemWatch.stop();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -