📄 testitem.java
字号:
package demo;
import java.io.IOException;
import javax.microedition.lcdui.ChoiceGroup;
public class TestItem {
public String Title; //题目的标题
public ChoiceGroup choicegroup; //存储题目的问句和选项
public String results[]; //存储测试结果
/******从数据数组中读取题目的各部分信息***********
* @参数 b..........存储文件数据的数组.
* @参数 start......b数组中存储本题目信息的起始位置
* @参数 total......b数组中所有信息的总长度
* @返回 b数组中,本题目的结束位置
*/
public int Load( byte b[], int start, int total ){
int end = start; //end存储一条信息的结束位置
/***************读题目的标题****************/
while( !( b[end] == '\r' && b[end + 1] == '\n') ){
//如果尚未遇到回车符和换行符,则end位置加1
end ++;
}
//遇到回车符和换行符循环结束,可读取一条信息
try{
//通过byte数组创建字符串
Title = new String(b, start, end - start, "UTF-8" );
}
catch (IOException e){}
//重新设置下一条信息的开始位置和结束位置
start = end + 2;
end = start;
/***************读题目的问句****************/
//创建choicegroup组件
choicegroup = new ChoiceGroup("", ChoiceGroup.EXCLUSIVE);
while( !( b[end] == '\r' && b[end + 1] == '\n') ){
end ++;
}
try{
String str = new String(b, start, end - start, "UTF-8" );
//用choicegroup的标签存储题目的问句
choicegroup.setLabel(str);
}
catch (IOException e){}
start = end + 2;
end = start;
/***************读题目的选项****************/
int num = 0; //记录选项的个数
//如果每一行的开头是大写字母,则表明该行是选项信息
while( b[start] >= 'A' && b[start] <= 'Z' ){
num ++;
while( !( b[end] == '\r' && b[end + 1] == '\n') ){
end ++;
}
try{
String str = new String(b, start, end - start, "UTF-8" );
choicegroup.append( str, null );
}
catch (IOException e){}
start = end + 2;
end = start;
}
/***************读题目的测试结果************/
//测试结果的数目与选项数目相同
results = new String[num];
for( int n = 0; n < num; n ++ ){
//有可能遇到文件末尾
while( end < total && ( !( b[end] == '\r' && b[end + 1] == '\n') ) ){
end ++;
}
try{
results[n] = new String(b, start, end - start, "UTF-8" );
}
catch (IOException e){}
start = end + 2;
end = start;
}
return end;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -