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

📄 biorhythmmidlet.java

📁 J2ME核心类及MIDlet类 MIDP用户界面对象 图形处理及低级事件处理 多线程编程 I/O及网络编程 数据库RMS编程 浮点数编程 多媒体及GAME API编程 安全、加密及
💻 JAVA
字号:

import java.io.*;
import java.util.Date;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;


public final class BiorhythmMIDlet extends MIDlet
    implements CommandListener  //, ItemStateListener
{

    public BiorhythmMIDlet()
    {
        super();
        canvas = new BiorhythmCanvas();
		canvas.addCommand( exitCmd );
		canvas.addCommand( showBirthCmd );
        canvas.setCommandListener(this);

		form = new BiorhythmForm( "生日" );
		form.addCommand( birthOkCmd );
		form.addCommand( birthCancelCmd );
		form.setCommandListener(this);
    }

    public void startApp()
    {
	
		readDate();
		if( date == null ) 
		{
			Display.getDisplay(this).setCurrent(form);
		}
		else
		{
			canvas.setBirthday(date);

			Display.getDisplay(this).setCurrent(canvas);
		}
	}

    public void pauseApp()
    {
    }

    public void destroyApp(boolean flag)
    {
    }

    public void commandAction(Command c, Displayable d)
    {
		if( c == exitCmd )
		{
			notifyDestroyed();
		}
		else if ( c == showBirthCmd )
		{
			form.setDate( date );
			Display.getDisplay(this).setCurrent(form);
		}
		else if ( c == birthOkCmd )
		{
			date = form.getDate( );
			if( date == null ) return;
			canvas.setBirthday(date);
			saveDate();

			Display.getDisplay(this).setCurrent(canvas);
		}
		else if ( c == birthCancelCmd )
		{
			Display.getDisplay(this).setCurrent(canvas);
		}
    }


    private void saveDate()
    {
        byte abyte0[];
        if(date == null)
            return;
        abyte0 = null;
        try
        {
            ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
            DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);
            dataoutputstream.writeLong(date.getTime());
            abyte0 = bytearrayoutputstream.toByteArray();
            dataoutputstream.close();
        }
        catch(IOException ioexception)
        {
            System.err.println(ioexception);
        }
        if(abyte0 == null)
            return;
		try{
			RecordStore recordstore = RecordStore.openRecordStore("Biorhythm", true);
			if( recordstore == null )
				return;

			int cnt = recordstore.getNumRecords();
			if( cnt == 0 )
			{
				recordstore.addRecord(abyte0, 0, abyte0.length);
			}
			else
			{
				recordstore.setRecord(1, abyte0, 0, abyte0.length);
			}
			recordstore.closeRecordStore();
		}catch( RecordStoreException recordstoreexception)
		{
			System.err.println(recordstoreexception);
		}
    }

    private void readDate()
    {
        byte abyte0[] = null;
        try
        {
            RecordStore recordstore = RecordStore.openRecordStore("Biorhythm", false);
            if(recordstore.getNumRecords() != 0)
                abyte0 = recordstore.getRecord(1);
            recordstore.closeRecordStore();
        }
        catch(RecordStoreException recordstoreexception)
        {
            System.err.println(recordstoreexception);
        }
        if(abyte0 != null)
            try
            {
                DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(abyte0));
                date = new Date(datainputstream.readLong());
                datainputstream.close();
            }
            catch(IOException ioexception)
            {
                System.err.println(ioexception);
            }
    }


    private Date date;
    private BiorhythmCanvas canvas;
	private BiorhythmForm form;

	private Command exitCmd = new Command( "Exit", Command.EXIT, 1 );
	private Command showBirthCmd = new Command("Birth", Command.SCREEN, 2 );
	private Command birthOkCmd = new Command("Ok", Command.EXIT, 1 );
	private Command birthCancelCmd = new Command( "Cancel", Command.SCREEN, 1 );

}

⌨️ 快捷键说明

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