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

📄 calendarcyy.java.bak

📁 一个手机日历程序的源代码,包括显示重要日期,节假日等
💻 BAK
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
//import calendar.*;

public class calendarcyy extends MIDlet implements CommandListener,ImportDateFilter,DateSelectListener
{
	private Command exitCommand,testCommand;
	private TextBox tb;
	private CalendarCanvas myCanvas;
	private int[][]holiday ={{1,1},{3,8},{5,1},{6,1},{10,1}};
	public calendarcyy()
	{
		exitCommand = new Command("Exit",Command.EXIT,9);
		testCommand = new Command("Calendar",Command.SCREEN,1);
		tb=new TextBox("demo","CalendarDemo MIDlet",40,0);
		tb.addCommand(exitCommand);
		tb.addCommand(textCommand);
		tb.setCommandListener(this);

		myCanvas = new CalendarCanvas(new Date());
		myCanvas.setImportDateFilter(this);
		myCanvas.setDateSelectListener(this);

		myCanvas.addCommand(exitCommand);
        myCanvas.setCommandListener(this);
	}

	protected void startApp() throws MIDletStateChangeException
	{
		Display.getDisplay(this).setCurrent(tb);
	}

	protected void pauseApp()
	{
	}

	protected void destroyApp(boolean p1 )
	{
	}

	public void commandAction(Command c,Displayable d)
	{
		if(c==exitCommand)
		{
			destroyApp(false);
			notifyDestroyed();
		}
		else if(c==testCommand)
		{
			Display.getDisplay(this).setCurrent(myCanvas);
		}
		else if(d == myCanvas)
		{
			myCanvas.commandAction(c,d);
		}
	}

	//实现ImportDateFilter接口,判断日期类型
	public int isImportantDate(Calendar date)
	{
		int dayOW=date.get(Calendar.DAY_OF_WEEK);
		if(dayOW==Calendar.SATURDAY||dayOW==Calendar.SUNDAY)
		{
			//周末作为假日
			return HOLIDAY;
		}
		int dayOM = date.get(Calendar.DAY_OF_MONTH);
		int month = date.get(Calendar.MONTH);
		for(int i=0;i<holiday.length;i++)
		{
			if(dayOM==holiday[i][1]&&month+1==holiday[i][0])
			   return HOLIDAY;
	    }
		if(dayOM==2&&month==0)
		{
			return BOTH;
		}

		if((dayOM==26||dayOM==27)&&month==0)
		{
			return IMPORTANTDAY;
		}
		return NORMALDAY;
	}

	public void dateSelected(CalendarCanvas c,Calendar date)
	{
		Display.getDisplay(this).setCurrent(tb);
		String dateStr = "date="+date.get(Calendar.YEAR)+"/";
		dateStr+=(date.get(Calendar.MONTH)+1)+"/"+date.get(Calendar.DAY_OF_MONTH);
		tb.setString(dateStr);
	}
};

⌨️ 快捷键说明

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