📄 testframe.java
字号:
package viewer;
import javax.swing.JScrollPane;
import java.awt.Rectangle;
import javax.swing.JTextArea;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.SystemColor;
import javax.swing.BorderFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import model.persistency.PersistentItem;
import controller.command.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import java.awt.Dimension;
import java.awt.Point;
/**
* <p>Title: </p>
* 测试框架
* <p>Description: </p>
* 是整个测试的父框架,同时又是UserFrame的子框架。
* 此框架有答案,测试的题目位于试卷的第几条的记录,和分数统计
* 对父类的next,submit,showscore,end命令做出反映
*/
public class TestFrame extends UserFrame{
static String answer; //答案
static int record;//记录
static float userScore; //分数
JButton jButton1 = new JButton();
JLabel score = new JLabel();
JButton jButton3 = new JButton();
JLabel jLabel2 = new JLabel();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
JButton jButton2 = new JButton();
public TestFrame(PersistentItem it) {
super();
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
jTextArea1.setText(it.getContent());//默认显示第一条
String s = new String();
s = s.valueOf(this.userScore);
score.setText(s);
record = 0 ;//记录
}
private void jbInit() throws Exception {
// this.setJMenuBar(jMenuBar1);
setSize(new Dimension(525, 440));
setTitle("OLTS System");
this.setResizable(true);
jButton1.setBounds(new Rectangle(357, 329, 100, 27));
jButton1.setActionCommand("showscore");
jButton1.setText("Show score");
jButton1.addActionListener(new TestFrame_jButton1_actionAdapter(this));
score.setBounds(new Rectangle(371, 279, 81, 32));
jButton3.setBounds(new Rectangle(38, 329, 76, 27));
jButton3.setBorder(null);
jButton3.setText("Next");
jButton3.addActionListener(new TestFrame_jButton3_actionAdapter(this));
jLabel2.setText("Score:");
jLabel2.setBounds(new Rectangle(360, 236, 46, 17));
jButton2.setBounds(new Rectangle(178, 329, 76, 27));
jButton2.setText("submit");
jButton2.addActionListener(new TestFrame_jButton2_actionAdapter(this));
jTextArea1.setEditable(false);
jTextArea1.setText("jTextArea1");
jScrollPane1.setBounds(new Rectangle(33, 50, 431, 168));
this.getContentPane().add(jButton1);
this.getContentPane().add(score);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jButton3);
this.getContentPane().add(jButton2);
this.getContentPane().add(jScrollPane1);
jScrollPane1.getViewport().add(jTextArea1);
super.nextMenuItem.addActionListener(new TestFrame_jButton3_actionAdapter(this));
super.nextButton.addActionListener(new TestFrame_jButton3_actionAdapter(this));
super.showMenuItem.addActionListener(new TestFrame_jButton1_actionAdapter(this));
super.showscoreButton.addActionListener(new TestFrame_jButton1_actionAdapter(this));
super.submitButton.addActionListener(new TestFrame_jButton2_actionAdapter(this));
super.submitMenuItem.addActionListener(new TestFrame_jButton2_actionAdapter(this));
super.endButton.addActionListener(new end_actionAdapter(this));
super.endMenuItem.addActionListener(new end_actionAdapter(this));
}
/**
* 处理父类next菜单项和next按键,调用NextCommand命令对父类的试卷属性进行处理
* 并将记录数得到
* @param e ActionEvent 事件
*/
public void jButton3_actionPerformed(ActionEvent e) {
this.setVisible(false);
NextCommand nc = new NextCommand(super.test);
this.record = nc.excute(this.record);
}
/**
* 处理显示分数菜单项和按钮,调用ShowScoreCommand命令对label score进行处理
* @param e ActionEvent
*/
public void jButton1_actionPerformed(ActionEvent e) {
ShowScoreCommand sc = new ShowScoreCommand();
score.setText(sc.excute(this.userScore));
}
/**
* 处理显示提交菜单项和按钮,调用SubmitCommand命令进行处理
* @param e ActionEvent
*/
public void jButton2_actionPerformed(ActionEvent e) {
jButton2.setEnabled(false);
super.submitButton.setEnabled(false);
super.submitMenuItem.setEnabled(false);
SubmitCommand sc = new SubmitCommand(super.test);
this.userScore = sc.excute(this.answer,this.record,this.userScore);
// jButton2.setEnabled(false);
}
/**
* 对父框架的end按钮和菜单项重新定义监听事件
* 销毁当前测试框架,生成UserFrame框架,并生成空试卷
* @param e ActionEvent
*/
public void end_actionPerformed(ActionEvent e){
this.dispose();
UserFrame frame = new UserFrame();
frame.test = null;
frame.setVisible(true);
}
}
//////////////////////////////////////////////////////////////////////////////
class TestFrame_jButton2_actionAdapter implements ActionListener {
private TestFrame adaptee;
TestFrame_jButton2_actionAdapter(TestFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class TestFrame_jButton1_actionAdapter implements ActionListener {
private TestFrame adaptee;
TestFrame_jButton1_actionAdapter(TestFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class TestFrame_jButton3_actionAdapter implements ActionListener {
private TestFrame adaptee;
TestFrame_jButton3_actionAdapter(TestFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class end_actionAdapter implements ActionListener {
private TestFrame adaptee;
end_actionAdapter(TestFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.end_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -