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

📄 courseform.java

📁 这是一个用j2me编写的手机管理系统。主要功能为课程表
💻 JAVA
字号:
package coursesManager;

import javax.microedition.lcdui.*;
import java.io.*;

public class CourseForm extends Form implements CommandListener {
	private Display display;

	private static Command CMD_BACK = new Command("返回", Command.BACK, 1);

	private Command CMD_SAVE;

	private Form mainForm;

	private TextField text_c, text_t, text_r, text_w;

	private String str_c, str_t, str_r, str_w;

	private int i, j;

	private static String coursesinfo[][][];

	private static boolean firstTime = true;

	private Record record;

	public CourseForm(String str, Display display, Form mainForm, int i, int j) {
		super(str);
		this.display = display;
		this.mainForm = mainForm;
		this.i = i;
		this.j = j;
		if (firstTime) {
			coursesinfo = new String[5][7][4];
			try {
				record = new Record("course");
				CoursesInfo cinfo[][] = new CoursesInfo[5][7];
				/*if(!record.empty()){
					
					record.deleteRecord();record.close();
				}*/
			
				if (record.empty()) {
					System.out.println("记录为空");
					ByteArrayOutputStream baos = new ByteArrayOutputStream();
					DataOutputStream dos = new DataOutputStream(baos);
					for (int m = 0; m < 5; m++) {
						for (int n = 0; n < 7; n++) {
							coursesinfo[m][n][0] = null;
							coursesinfo[m][n][1] = null;
							coursesinfo[m][n][2] = null;
							coursesinfo[m][n][3] = null;
							cinfo[m][n] = new CoursesInfo();
							cinfo[m][n].str_c = "empty";
							cinfo[m][n].str_t = "empty";
							cinfo[m][n].str_r = "empty";
							cinfo[m][n].str_w = "empty";
							//写入数据时错误
							cinfo[m][n].writeData(dos);
						}
					}
					record.setRecord(baos.toByteArray());
					record.close();
				}
			} catch (Exception e) {
				System.out.println("创建信息失败" + e);
			}
			// 读取所有信息
			try {
				record = new Record("course");
				CoursesInfo cinfo[][] = new CoursesInfo[5][7];
				if (!record.empty()) {
					System.out.println("记录不为空");
					byte[] data = record.getRecord();
					//System.out.println(""+data.length+"asdfasdfasdfsadf");
					ByteArrayInputStream bais = new ByteArrayInputStream(data);
					DataInputStream dis = new DataInputStream(bais);
					for (int m = 0; m < 5; m++) {
						for (int n = 0; n < 7; n++) {
							cinfo[m][n] = new CoursesInfo();
							cinfo[m][n].readData(dis);
							coursesinfo[m][n][0] = cinfo[m][n].str_c;
							coursesinfo[m][n][1] = cinfo[m][n].str_t;
							coursesinfo[m][n][2] = cinfo[m][n].str_r;
							coursesinfo[m][n][3] = cinfo[m][n].str_w;
						}
					}
					record.close();
				}
			} catch (Exception e) {
				System.out.println("读取信息失败" + e);
			}
			firstTime = false;
		}
		str_c = coursesinfo[this.i][this.j][0];
		str_t = coursesinfo[this.i][this.j][1];
		str_r = coursesinfo[this.i][this.j][2];
		str_w = coursesinfo[this.i][this.j][3];
		CMD_SAVE = new Command("保存", Command.OK, 2);
		this.addCommand(CMD_BACK);
		this.addCommand(CMD_SAVE);
		this.setCommandListener(this);
		text_c = new TextField("课程名称:\n", str_c, 10, TextField.ANY);
		text_t = new TextField("教师:\n", str_t, 10, TextField.ANY);
		text_r = new TextField("教室:\n", str_r, 10, TextField.ANY);
		text_w = new TextField("作业:\n", str_w, 10, TextField.ANY);
		append(text_c);
		append(text_t);
		append(text_r);
		append(text_w);
	}

	public void commandAction(Command com, Displayable dis) {
		if (com == CMD_BACK) {
			display.setCurrent(mainForm);
		} else if (com == CMD_SAVE) {
			coursesinfo[i][j][0] = text_c.getString();
			coursesinfo[i][j][1] = text_t.getString();
			coursesinfo[i][j][2] = text_r.getString();
			coursesinfo[i][j][3] = text_w.getString();
			record = new Record("course");
			CoursesInfo cinfo[][] = new CoursesInfo[5][7];
			try {
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				DataOutputStream dos = new DataOutputStream(baos);
				for (int m = 0; m < 5; m++) {
					for (int n = 0; n < 7; n++) {
						cinfo[m][n] = new CoursesInfo();
						cinfo[m][n].str_c = coursesinfo[m][n][0];
						cinfo[m][n].str_t = coursesinfo[m][n][1];
						cinfo[m][n].str_r = coursesinfo[m][n][2];
						cinfo[m][n].str_w = coursesinfo[m][n][3];
						cinfo[m][n].writeData(dos);
					}
				}
				record.setRecord(baos.toByteArray());
				record.close();

			} catch (Exception e) {
				System.out.println("创建信息失败" + e);
			}
		}

	}

}

⌨️ 快捷键说明

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