⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clasdetailform.java

📁 一款Java版的课程表软件
💻 JAVA
字号:
package ui;

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 = { "第一、二节", "第三、四节", "第五、六节", "第七、八节", };
	// 夏季时间
	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;// 内容
	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("数据转换!");
	// 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转换为Data
	private String contentsToDataString() {
		String tmpStr = "";
		for (int i = 0; i < 4; i++) {
			clasContent[i] = courseItem[i].getContent();
			tmpStr += clasContent[i] + '$';
		}

		return tmpStr;
	}

	// 将从Data装换成课程数据,每个数据段以‘$’做结尾
	private void convertDataToContent(String s) {
		String tmpStr = s;
		System.out.println("数据转换!");
		for (int i = 0; i < 4; i++) {
			tmpStr = s.substring(0, s.indexOf('$'));
			clasContent[i] = tmpStr;
			s = s.substring(s.indexOf('$') + 1, s.length());

		}
	}

	// 读取数据到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();
		}

	}

	// 将数据写入对应 班级名RS里的对应星期rc
	private void writeClasContentToData() {
		String tmpStr = null;
		byte[] wByte = null;
		// 得到DataString
		tmpStr = contentsToDataString();
		// 转换为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));
		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -