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

📄 manager.java

📁 大学生日程管理系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import java.io.IOException;
import java.util.Date;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreNotOpenException;

/*
 * 创建日期 2006-12-6
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */

/**
 * @author Administrator
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class manager extends MIDlet implements CommandListener{
//构造界面和处理界面转换逻辑
	
	 //以下常量代表屏幕的各个显示阶段
	final int MAIN_MENU=0;  //主菜单
	final int SHOW_DATE_MENU=1;//显示日程
	final int SELECT_DAY=2;
	final int COURSE_MANAGER_MENU=3;//课程管理
	final int DATE_MANAGER_MENU=4;//日期管理
	final int DIARY_MENU=5;//日记
	final int SETTING_MENU=6;//设置
	final int NEW_TERM=7;//新学期
	final int SET_NEW_TERM=8;
	final int ADD_COURSE_1=9;//增加课程
	final int ADD_COURSE_2=10;
	final int ADD_COURSE_3=11;
	final int MODIFY_COURSE_1=12;//管理课程
	final int MODIFY_COURSE_2=13;
	final int ADD_NOTE_1=14;
	final int ADD_NOTE_2=15;//增加提醒
	final int DELETE_NOTE=16;//删除提醒
	final int ADD_IMPORTANT_DATE=17;//增加节日
	final int PRESENT_IMPORTANT_DATE=18;//已登记节日
	final int ADD_NEW_DIARY_1=19;//增加日记
	final int ADD_NEW_DIARY_2=20;
	final int READ_DIARY_1=21;//查看已写
	final int READ_DIARY_2=22;
	final int ABOUT=23;
	final int SHOW_ALL_NOTE=24;
	final int SHOW_DATA=25;
	final int WORD_TO_ME=26;
    final int SET_PASSWORD=27;
    final int LOGIN=28;
    final int DIARY_ADD=29;
    
	private int status;//当前所在状态
	
	
	public static StringBuffer information;
	
	public static Display display;
	
	public static Form form;
	
	public static List list;
	
	//public static RecordStore CStore ;//课程类实例
	
	//public static RecordStore note_diary;//提醒和日记类实例
	
	//重要日子类实例
	
	private static Alert alert;
	private int dix; 
	private int weekday;//星期几
	private int classth;//第几节课
	
	private Date begin;
	private Date end;//保存新学期开始结束时间
	private Ticker ticker;
	private DateField datefield1;
	private DateField datefield2;
	private Displayable pre_dis;
	private TextField textfield1;
	private TextField textfield2;
	private TextField textfield3;
	private TextField textfield4;
	private TextBox textbox;
	private ChoiceGroup choicegroup1;
	private int cweekday;
	private int cclassth;
	
	private date[] dates;
	private DateManager calendar;
	private date adate;
	private Date now_date;
	private boolean deletenow;
	private String password;
	
	 Command OkCmd;
	
	 Command BackCmd ;
	
	 Command HelpCmd ;
	 Command ContinueCmd;
	 Command ToMainCmd;
     
	 Command SureCmd;
	
	
	
	public manager() {
		SureCmd=new Command ("提交",Command.SCREEN,2);
		OkCmd =new Command ("选择",Command.SCREEN,1);
		BackCmd =new Command ("返回",Command.SCREEN ,3);
		HelpCmd =new Command ("帮助",Command.SCREEN ,3);
		ContinueCmd=new Command("继续",Command.SCREEN ,2);
		ToMainCmd=new Command("主菜单",Command.SCREEN ,1);
		status=-1;
		new Note_diary();
		//note_diary=Note_diary.note_diary;
		new WeekInfStore();
		//CStore=WeekInfStore.weekinf;
		display=Display.getDisplay(this);
		// TODO 自动生成构造函数存根
	}
	
	void show_inf2(String inf){
		Alert show=new Alert("信息",inf,null,AlertType.CONFIRMATION);
		show.setTimeout(2000);
		display.setCurrent(show);
	}
	
	void show_inf(String inf){
		Alert show=new Alert("信息",inf,null,AlertType.CONFIRMATION);
		show.setTimeout(Alert.FOREVER);
		display.setCurrent(show);
	}
	boolean is_today(Date date){
		boolean is_today1=true;
		Date d=new Date();
		int[]a=DateManager.get_year_mon_day(d);
		int[]b=DateManager.get_year_mon_day(date);
		
		
		for(int i=0;i<3;i++){
			if(a[i]!=b[i]){
				is_today1=false;
				break;
			}
		}
		return is_today1;
		
	}
	String get_weekday(Date date){
		String s=new String();
		switch (DateManager.weekday( date)){
		case 7:
			s="星期天";
		    break;
		case 1:
			s="星期一";
			break;
		case 2:
			s="星期二";
			break;
		case 3:
			s="星期三";
			break;
		case 4:
			s="星期四";
			break;
		case 5:
			s="星期五";
			break;
		case 6:
			s="星期六";
			break;
		}
		return s;
	}

	void show_date_inf(Date adate) {//显示当天消息,重点实现!!
		date adaycourse=new date(true);
		int[] b=DateManager.get_year_mon_day(adate);
		String time=b[0]+"年"+b[1]+"月"+b[2]+"日 ";
		
		boolean has_course=false;
	    boolean today=is_today(adate);
	        information=new StringBuffer();
			StringBuffer t_string=new StringBuffer();
			t_string.append(time);
			
		
			int num=Note_diary.get_num(b[0],b[1],b[2]);
			if(num>0){
				
			dates=new date[num];
			dates=Note_diary.get(b[0],b[1],b[2]);
			
				for(int i=0;i<dates.length;i++){
					if(dates[i].getWhich()==1){
						if(today){
							t_string.append(" ");
						   t_string.append(dates[i].getName());
						   t_string.append("快乐!");
						}
						else{
							t_string.append(" ");
							t_string.append(dates[i].getName());
							
						}
					}
				}
			}
			
			ticker=new Ticker(t_string.toString());
			
			
			
			if(DateManager.in_term( adate)){
				
				int temp=0;
				try {
					temp = DateManager.get_weekth(adate);
				} catch (RecordStoreException e3) {
					// TODO 自动生成 catch 块
					e3.printStackTrace();
				} catch (Exception e3) {
					// TODO 自动生成 catch 块
					e3.printStackTrace();
				}
				if(today){
					
					try {	
							information.append("今天是");
						    information.append(temp);
						    information.append("周");
						    information.append(get_weekday(adate));
						    information.append("您的课程有:\n");
						
					} catch (Exception e2) {
						// TODO 自动生成 catch 块
						e2.printStackTrace();
					}
					
					
				}
				else
				{	
					try {	
							information.append("这天是");
						    information.append(DateManager.get_weekth(adate));
						    information.append("周");
							information.append(get_weekday(adate));
							information.append("您的课程有:\n");
						
					} catch (RecordStoreException e2) {
						// TODO 自动生成 catch 块
						e2.printStackTrace();
					} catch (Exception e2) {
						// TODO 自动生成 catch 块
						e2.printStackTrace();
					}
					
				}
				
			
				try {
					int d[]=WeekInfStore.get_term_date();
				} catch (Exception e) {
				
					e.printStackTrace();
				}
				try {
					//adaycourse=WeekInfStore.get(DateManager.weekday(date),2);
					adaycourse=WeekInfStore.get(DateManager.weekday(adate),temp);
				} catch (Exception e1) {
					
					e1.printStackTrace();
				}
				if(!adaycourse.course[0].equals("无课程")){
					information.append("早上第一节:\n");
					information.append(adaycourse.course[0]);
					information.append("\n");
					information.append("教室:");
					information.append(adaycourse.where[0]);
					information.append("\n");
					has_course=true;
				}
				
				if(!adaycourse.course[1].equals("无课程")){
					information.append("早上第二节:\n");
					information.append(adaycourse.course[1]);
					information.append("\n");
					information.append("教室:");
					information.append(adaycourse.where[1]);
					information.append("\n");
					has_course=true;
				}
				if(!adaycourse.course[2].equals("无课程")){
					information.append("下午第一节:\n");
					information.append(adaycourse.course[2]);
					information.append("\n");
					information.append("教室:");
					information.append(adaycourse.where[2]);
					information.append("\n");
					has_course=true;
				}
				if(!adaycourse.course[3].equals("无课程")){
					information.append("下午第二节:\n");
					information.append(adaycourse.course[3]);
					information.append("\n");
					information.append("教室:");
					information.append(adaycourse.where[3]);
					information.append("\n");
					has_course=true;
				}
				if(!adaycourse.course[4].equals("无课程")){
					information.append("晚上:\n");
					information.append(adaycourse.course[4]);
					information.append("\n");
					information.append("教室:");
					information.append(adaycourse.where[4]);
					information.append("\n");
					has_course=true;
				}
				
				if(!has_course){
					if(today)
					    information.append("恭喜,今天您不用上课。\n");
					else
						 information.append("恭喜,这一天您不用上课。\n");
				}
				
			}
			else{
				if(today)
					information.append("今天不在任何学期内,或者你还没设置学期。\n ");
				else
					information.append("当天不在任何学期内,或者你还没设置学期。\n ");
				
			}
            if(num<=0){
            	
				String temp=WeekInfStore.get_word(false);
				if(temp!=null && !temp.equals("无")){
					information.append(temp);
					information.append("\n");
				}
			}
            
			if(num>0){
				
				for(int i=0;i<dates.length;i++){
					if(dates[i].getWhich()==2 && dates[i].getYear()==b[0]){
						if(today)
						    information.append("注意:");
						else
							information.append("注意:");
						information.append(dates[i].getContent());
						information.append("\n");
					}
				}
			
				String temp=WeekInfStore.get_word(false);
				if(temp!=null && !temp.equals("无")){
					information.append(temp);
					information.append("\n");
				}
				
				for(int i=0;i<dates.length;i++){
					if(dates[i].getWhich()==3 && dates[i].getYear()==b[0]){
						if(today)
						     information.append("您今天写了日记,标题是《");
						else
							information.append("您这天写了日记,标题是《");
						information.append(dates[i].getName());
						information.append("》\n");
					}
				}
			}
			
			
	}
	

	/* (非 Javadoc)
	 * @see javax.microedition.midlet.MIDlet#startApp()
	 */
	protected void startApp() {
		// TODO 自动生成方法存根
		Date d=new Date();
		if(status==-1){
			try {
				show_date_menu(d);
			} catch (Exception e) {
				
				main_menu();
				
				int[] b=DateManager.get_year_mon_day(d);
				String time=b[0]+"年"+b[1]+"月"+b[2]+"日 ";
		
			}
		}
		else     
		main_menu();
	}

	/* (非 Javadoc)
	 * @see javax.microedition.midlet.MIDlet#pauseApp()
	 */
	protected void pauseApp() {
		// TODO 自动生成方法存根

	}

	/* (非 Javadoc)
	 * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
	 */
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO 自动生成方法存根

	}
	
	void main_menu(){
		String[] s={"显示日程安排","日记","日期管理","课程管理","统计","关于本软件","退出"};
		list=new List("日程管理系统",List.IMPLICIT  ,s ,null);
		
		// 侦听按键响应
		list.setCommandListener(this);
		display.setCurrent(list);
		
		status=MAIN_MENU;
	}
	void show_date_menu(Date d) {
		form =new Form("当日信息");
		show_date_inf(d);
		form.append(information.toString());
		form.setTicker(ticker);
		Command nextCmd=new Command("下一天",Command.SCREEN,2);
		Command preCmd=new Command("前一天",Command.SCREEN ,2);
		Command selectCmd=new Command("选择日期",Command.SCREEN,3);
		Command add_diaryCmd=new Command("写日记",Command.SCREEN ,1);
		Command add_noteCmd=new Command("增加提醒",Command.SCREEN ,2);
		Command show_dirayCmd=new Command("查看日记",Command.SCREEN ,5);
		
		form.addCommand(ToMainCmd);
		form.addCommand(add_noteCmd);
		form.addCommand(nextCmd);
		form.addCommand(preCmd);
		form.addCommand(selectCmd);
		form.addCommand(show_dirayCmd);
		if(is_today(d)){
			form.addCommand(add_diaryCmd);
		}
		form.setCommandListener(this);
		now_date=d;
		pre_dis=form;
		display.setCurrent(form);
		status=SHOW_DATE_MENU;
	}
	void select_day(){
		form=new Form("选择日期");
		datefield1=new DateField("选择日期",DateField.DATE);
		datefield1.setDate(new Date());
		form.append(datefield1);
		form.addCommand(OkCmd);
		form.setCommandListener(this);
		pre_dis=form;
		display.setCurrent(form);
		status=SELECT_DAY;
	}
	
	void course_manager_menu(){
		String[] s={"增加课程","删除课程","新学期"};
		list=new List("课程管理", List.IMPLICIT ,s,null);
		
		
		list.addCommand(BackCmd);

		// 侦听按键响应
		list.setCommandListener(this);
		pre_dis=list;
		display.setCurrent(list);
		
		status=COURSE_MANAGER_MENU;
	

	}
	
	void date_manager_menu(){
		String[] s={"增加提醒","显示所有提醒","删除提醒","增加节日","已记录的节日"};
		list=new List("日期管理",List.IMPLICIT ,s,null);
		
		list.addCommand(BackCmd);
		list.setCommandListener(this);
		pre_dis=list;
		display.setCurrent( list);
		status=DATE_MANAGER_MENU;
	}
	
	void diary_menu(){
		String[] s={"写新日记" ,"查看已写日记","座右铭","设置密码"};
		list=new List("日记",List.IMPLICIT ,s,null);
		
		list.addCommand(BackCmd);
		list.setCommandListener(this);
		pre_dis=list;
		display.setCurrent( list);
		status=DIARY_MENU;
	}
	void about(Displayable d){
		About.showAbout(display,d);
		
	}
	
	void show_data(){
		information=new StringBuffer();
		form=new Form("统计");
		information.append("你的手机当前有");
		int i=Note_diary.get_num(1);
		information.append(i);
		information.append("条重要节日记录,");
		i=Note_diary.get_num(2);
		information.append(i);
		information.append("条提醒,");
		i=Note_diary.get_num(3);
		information.append(i);
		information.append("篇日记\n");
		Date date=new Date();
		if(DateManager.in_term( date)){
			int[] d=new int[8];
			d=WeekInfStore.get_term_date();
			i=DateManager.Days(DateManager.set_a_date(d[0],d[1],d[2]),date);
			information.append("本学期于");
			information.append(d[0]);
			information.append("年");
			information.append(d[1]);
			information.append("月");
			information.append(d[2]);
			information.append("日");
			information.append("开始,已过去");
			information.append(i);
			information.append("天。本学期将于");
			information.append(d[3]);
			information.append("年");
			information.append(d[4]);
			information.append("月");
			information.append(d[5]);
			information.append("日");
			information.append("结束,距离结束还有");
			i=DateManager.Days(date,DateManager.set_a_date(d[3],d[4],d[5]));
			information.append(i);
			information.append("天。\n继续努力吧。生活是美好的。");
		}
		form.append(information.toString());
		form.addCommand(BackCmd);
		form.setCommandListener( this);
		pre_dis=form;
		display.setCurrent( form);
		status=SHOW_DATA;
	}
	
	void new_term(){
		form=new Form("警告!!!");
		form.append("添加新学期将清除所有旧学期的课程信息!!!!!");
		form.append("你真的确定添加吗????");
		form.addCommand(OkCmd);
		form.addCommand(BackCmd);
		form.setCommandListener( this);
		pre_dis=form;
		display.setCurrent( form);
		status=NEW_TERM;

⌨️ 快捷键说明

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