package ewords;
import mylcdui.*;
import java.util.*;
import javax.microedition.lcdui.*;
import utils.*;
import java.util.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class MainForm extends TForm {
public MainForm() {
super();
//doDebugTest();
if (App._.config.nowWordIndex == 0)
App._.config.nowWordIndex = 1;
pageCtrl.items = new String[]{"早晨温习", "每日新学", "每日复习", "上周重温"};
addControl(pageCtrl, defaultRowHeight(), defaultRowHeight()*2+5);
listBox.items = FuncDesces;
addControl(listBox, defaultRowHeight()+pageCtrl.height, getHeight()-defaultRowHeight()*2 - pageCtrl.height);
TLabel title = new TLabel();
title.text = "轻松背单词";
title.alignment = TLabel.ALIGN_CENTER;
addControl(title, 0);
addCommandBar("进入", "退出");
TTimeLabel lblTime = new TTimeLabel(); //时钟
lblTime.forecolor = Colors.BLUE;
lblTime.alignment = TLabel.ALIGN_CENTER;
lblTime.format = "hh:MM";
addControl(lblTime, getHeight()-defaultRowHeight());
lblHint.alignment = TLabel.ALIGN_CENTER;
lblHint.backcolor = Colors.TRANSPARENT;
lblHint.forecolor = Colors.RED;
addControl(lblHint, getHeight()-defaultRowHeight());
loadBookWordList();
}
private TLabel lblHint = new TLabel();
public String[] bookWordList;
private int bookWordListMin;
private int bookWordListMax;
//获取书籍内容
public void loadBookWordList() {
String[] tmpList = DicWord.loadWordList("BookWordList.dic");
bookWordListMin = Integer.parseInt(tmpList[0]);
bookWordListMax = Integer.parseInt(tmpList[1]);
String[] bookWordListTmp = new String[tmpList.length-2];
System.arraycopy(tmpList, 2, bookWordListTmp, 0, bookWordListTmp.length);
if (bookWordListMax <= App._.config.nowWordIndex + App._.config.wordCountPerDay *3) {
int n = (bookWordListMax - App._.config.nowWordIndex) / App._.config.wordCountPerDay;
lblHint.text = "请" + Integer.toString(n) +"日内更新词库";
lblHint.repaint();
}
bookWordList = bookWordListTmp;
}
//获取指定范围的单词列表,书籍中没有则返回null
private String[] loadStudingWords(int startIndex, int wordCount) {
if (bookWordList == null) {
lblHint.text = "正在读取词库...";
lblHint.repaint();
return null;
}
if ((startIndex < bookWordListMin) || (startIndex+wordCount-1 > bookWordListMax)) {
lblHint.text = "请立即更新词库";
lblHint.repaint();
return null;
}
String[] ret = new String[wordCount];
System.arraycopy(bookWordList, startIndex-bookWordListMin, ret, 0, ret.length);
return ret;
}
//获取当前的日期值,凌晨2:00之前计入前一天
public static int getNowDate() {
int today = NwDate.Today().toIntBits();
TimeZone tz = TimeZone.getTimeZone("GMT+8:00");
Calendar calendar = Calendar.getInstance(tz);
Date now = new Date(System.currentTimeMillis());
calendar.setTime(now);
if (calendar.get(Calendar.HOUR_OF_DAY) < 2)
return today -1;
else
return today;
}
//获取当前应学习的单词列表,书籍中没有则返回null
private String[] loadStudingWords() {
int today = getNowDate();
switch (pageCtrl.itemindex) {
case 0: //早晨温习
AppConfig.DayHisWords his = App._.config.getDayHisWords(today-1);
if (his == null) {
lblHint.text = "昨天未新学";
lblHint.repaint();
return null;
}
return loadStudingWords(his.wordStartIndex, his.wordCount);
case 1: //每日新学
AppConfig.DayHisWords his1 = App._.config.getDayHisWords(today);
if (his1 != null)
return loadStudingWords(his1.wordStartIndex, his1.wordCount);
return loadStudingWords(App._.config.nowWordIndex, App._.config.wordCountPerDay);
case 2: //每日复习
AppConfig.DayHisWords his2 = App._.config.getDayHisWords(today-2);
String[] his2Words = null;
if (his2 != null)
{
his2Words = loadStudingWords(his2.wordStartIndex, his2.wordCount);
if (his2Words == null) return null;
}
AppConfig.DayHisWords his4 = App._.config.getDayHisWords(today-4);
String[] his4Words = null;
if (his4 != null)
{
his4Words = loadStudingWords(his4.wordStartIndex, his4.wordCount);
if (his4Words == null) return null;
}
if ((his2Words == null)&&(his4Words == null)) {
lblHint.text = "前天未新学";
lblHint.repaint();
return null;
}
return arrayMerge(new String[][]{his2Words, his4Words});
case 3: //上周重温
//复习上一周所学全部新单词(此类单词若新学和前2次复习均无误,可略过)
int lastMonday = today - (NwDate.valueOf(today)).getWeekDay() - 6;
String[][] perDayWords = new String[7][];
for (int i=0; i < 7; i++) {
AppConfig.DayHisWords hisi = App._.config.getDayHisWords(lastMonday+i);
if (hisi == null) {
perDayWords[i] = null;
continue;
}
String[] hisiDayWords = loadStudingWords(hisi.wordStartIndex, hisi.wordCount);
if (hisiDayWords == null) return null;
Vector dayWords = new Vector();
for (int k=0; k < hisi.wordCount; k++) {
if (hisi.ifPass[k] && hisi.ifPass1[k] && hisi.ifPass2[k])
;
else
dayWords.addElement(hisiDayWords[k]);
}
if (dayWords.size() == 0)
perDayWords[i] = null;
else {
perDayWords[i] = new String[dayWords.size()];
dayWords.copyInto(perDayWords[i]);
}
}
String[] ret = arrayMerge(perDayWords);
if (ret.length == 0) {
lblHint.text = "上周未新学";
lblHint.repaint();
return null;
}
return ret;
}
return null;
}
//数组合并
private String[] arrayMerge(String[][] a) {
int nCount = 0;
for (int i=0; i < a.length; i++) {
if (a[i] != null)
nCount += a[i].length;
}
String[] ret = new String[nCount];
int nIndex = 0;
for (int i=0; i < a.length; i++) {
if (a[i] != null) {
System.arraycopy(a[i], 0, ret, nIndex, a[i].length);
nIndex += a[i].length;
}
}
return ret;
}
//保存测验成绩
public void saveExamHis(boolean[] examIsOK) {
examIsOK = unRandSortWords(examIsOK);
int today = getNowDate();
switch (pageCtrl.itemindex) {
case 0: //早晨温习
App._.config.savetDayHisWords(today - 1, 1, examIsOK);
break;
case 1: //每日新学
App._.config.savetDayHisWords(today, 0, examIsOK);
break;
case 2: //每日复习
j2me版背单词程序
4星 · 超过85%的资源 需积分: 3 29 浏览量
2010-01-11
13:55:02
上传
评论
收藏 14.76MB ZIP 举报
wolffool
- 粉丝: 6
- 资源: 3
最新资源
- 杨辉三角(Pascal's Triangle)是一个在数学中非常著名的数列,它以一种特定的模式排列数字,内容以5种代码实例实现
- yolov5数据集:CT图像肾脏、结石检测(2类别,包含训练集、验证集)
- 电力102规约请求报文实录
- RTL8723 linux+安卓驱动 2020版本
- ISO 26262 道路车辆-功能安全-系统级产品开发
- 数据挖掘期末题 选择填空简答
- EKF在CTRV模型上的建模推导
- 用于:https://laoshifu.blog.csdn.net/article/details/138191428 多层创建
- 电力102规约(电能累计量的传输规约)培训
- 「常用」E9外部流程接口
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈