?? clasdetailform.java
字號:
package ui;
// Download by http://www.codefans.net
import java.io.UnsupportedEncodingException;
import java.util.Date;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;
import ui.unit.CourseItem;
import clasAn.ClasAnsistMIDlet;
import clasAn.core.GUIInfo;
public class ClasDetailForm extends Form implements CommandListener {
private ClasAnsistMIDlet clasAnsistMIDlet;
private Command cmdBack;
private Display display;
// 班級名
private String gradeName;
// 星期
private int weekDay;
// 標簽
private final String[] decString = { "第一、二節(jié)", "第三、四節(jié)", "第五、六節(jié)", "第七、八節(jié)", };
// 夏季時間
private final String[] sumyTime = { "08:00", "10:00", "14:00", "15:50", };
// 冬季時間
private final String[] wintTime = { "08:00", "10:00", "13:50", "15:40", };
private String[] clasContent = GUIInfo.NULL_CONTENT;// 內(nèi)容
private CourseItem[] courseItem = new CourseItem[4];
public ClasDetailForm(String gradeName, int weekDay, ClasAnsistMIDlet c) {
super(gradeName + ":" + GUIInfo.WEEKDAYS[weekDay]);
this.clasAnsistMIDlet = c;
this.gradeName = gradeName;
this.weekDay = weekDay;
display = Display.getDisplay(clasAnsistMIDlet);
cmdBack = new Command(GUIInfo.COMMAND_BACK, Command.BACK, 1);
this.setCommandListener(this);
this.addCommand(cmdBack);
System.out.println("讀取課程");
// test("aaaaaaa$bbbb$cccc$dddd$");
readClassesToForm();
/*
* 以下是時令控制
*/
Date nowDate = new Date();
nowDate.setTime(new Date().getTime());
String currentTime = nowDate.toString();
System.out.println(currentTime.substring(4, 7));
currentTime = currentTime.substring(4, 7);
int summerORWinter = 1;
for (int i = 0; i < 12; i++) {
if (currentTime.endsWith(GUIInfo.MONTHS[i])) {
summerORWinter = i + 1;
System.out.println(summerORWinter);
break;
}
}
this.append("上午:\n");
for (int i = 0; i < decString.length; i++) {
if ((summerORWinter >= 10 && summerORWinter <= 12)
|| (summerORWinter >= 1 && summerORWinter < 5)) {
// 冬季時間
this.courseItem[i] = new CourseItem(decString[i], wintTime[i],
clasContent[i],GUIInfo.CONTENT_LENGTH, this.display);
} else {// 夏季時間
this.courseItem[i] = new CourseItem(decString[i], sumyTime[i],
clasContent[i], GUIInfo.CONTENT_LENGTH, this.display);
}
System.out.println("OK");
if (i == 2)
this.append("\n下午:\n");
this.append(courseItem[i]);
}
}
// private void test(String s){
// String tmpStr=s;
// System.out.println("數(shù)據(jù)轉(zhuǎn)換!");
// for(int i=0;i<4;i++){
// tmpStr=s.substring(0,s.indexOf('$'));
// clasContent[i]=tmpStr;
// s=s.substring(s.indexOf('$')+1,s.length());
//
// }
// }
// 將clasContent轉(zhuǎn)換為Data
private String contentsToDataString() {
String tmpStr = "";
for (int i = 0; i < 4; i++) {
clasContent[i] = courseItem[i].getContent();
tmpStr += clasContent[i] + '$';
}
return tmpStr;
}
// 將從Data裝換成課程數(shù)據(jù),每個數(shù)據(jù)段以‘$’做結(jié)尾
private void convertDataToContent(String s) {
String tmpStr = s;
System.out.println("數(shù)據(jù)轉(zhuǎn)換!");
for (int i = 0; i < 4; i++) {
tmpStr = s.substring(0, s.indexOf('$'));
clasContent[i] = tmpStr;
s = s.substring(s.indexOf('$') + 1, s.length());
}
}
// 讀取數(shù)據(jù)到Form
private void readClassesToForm() {
int gradesNum = 0;
String tmpStr = null;
try {
RecordStore rsDate = RecordStore.openRecordStore(this.gradeName,
false);
gradesNum = rsDate.getNumRecords();
if (gradesNum != 0) {
try {
tmpStr = new String(rsDate.getRecord(this.weekDay + 1),
"UTF-8");
convertDataToContent(tmpStr);
rsDate.closeRecordStore();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (RecordStoreFullException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
System.out.println("沒找到" + this.gradeName);
this.clasContent=GUIInfo.NULL_CONTENT;
// e.printStackTrace();
} catch (RecordStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 將數(shù)據(jù)寫入對應(yīng) 班級名RS里的對應(yīng)星期rc
private void writeClasContentToData() {
String tmpStr = null;
byte[] wByte = null;
// 得到DataString
tmpStr = contentsToDataString();
// 轉(zhuǎn)換為bytes
try {
wByte = tmpStr.getBytes("UTF-8");
RecordStore rsDate = RecordStore.openRecordStore(this.gradeName,
true);
int rcNums = rsDate.getNumRecords();
if (rcNums == 0) {
iniRecStore();
rsDate.setRecord(this.weekDay + 1, wByte, 0, wByte.length);
} else
rsDate.setRecord(this.weekDay + 1, wByte, 0, wByte.length);
rsDate.closeRecordStore();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreFullException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreNotOpenException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidRecordIDException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//存儲初始化
private void iniRecStore() {
byte[] wByte = null;
try {
wByte = ("<空>$<空>$<空>$<空>$").getBytes("UTF-8");
RecordStore rsDate = RecordStore.openRecordStore(this.gradeName, true);
for (int i = 0; i < 7; i++) {
rsDate.addRecord(wByte, 0, wByte.length);
}
rsDate.closeRecordStore();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreFullException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreNotOpenException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RecordStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void commandAction(Command c, Displayable arg1) {
if (c == cmdBack) {
System.out.println(GUIInfo.COMMAND_BACK);
for (int i = 0; i < courseItem.length; i++) {
if (courseItem[i].isEdited()) {
this.writeClasContentToData();
System.out.println("編輯了!");
break;
}
}
display.setCurrent(new WeekDayList(this.gradeName,
this.clasAnsistMIDlet));
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -