3

我有一个 Java ME 日历,但我希望能够显示来自 PIM 功能的事件。

有人可以给我一些帮助吗?

import javax.microedition.pim.Event;
import javax.microedition.pim.EventList;
import javax.microedition.pim.PIM;
import javax.microedition.pim.PIMException;
import javax.microedition.pim.PIMItem;

public class PopulateDatabase 
{

/** This method adds test data to the calendar database. Note the special
 *  treatment of dates. You will need to reverse this process when retrieving
 *  date values.
 */

static void populate() 
{
    PIM pim = PIM.getInstance();
    EventList eventList = null;
    Event[] events = new Event[10];

    try 
    {
        eventList = (EventList) pim.openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);            

    } catch (PIMException e) 
    {
        System.err.println("Error accessing calendar database");
        return;
    } catch (SecurityException e) {
        System.err.println("Security exception (writing to calendar database)");
        return;
    }
    // The following code assumes we have checked various fields are available....

    // Event 1 - Visit parents on 1st Sept. (all day event)
    events[0] = eventList.createEvent();
    events[0].addDate(Event.START, PIMItem.ATTR_NONE, 1346500800000L / 10);
    events[0].addDate(Event.END, PIMItem.ATTR_NONE, 1346500800000L / 10);
    events[0].addString(Event.LOCATION, PIMItem.ATTR_NONE, "Wales");
    events[0].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Visit parents");
    events[0].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PRIVATE);

    // Event 2 - PMD lecture on 3rd Sept. 10-11
    events[1] = eventList.createEvent(); 
    events[1].addDate(Event.START, PIMItem.ATTR_NONE, 1346666400000L / 10);
    events[1].addDate(Event.END, PIMItem.ATTR_NONE, 1346670000000L / 10);
    events[1].addString(Event.LOCATION, PIMItem.ATTR_NONE, "G0.54");
    events[1].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Programming for Mobile Devices lecture");
    events[1].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PUBLIC);

    // Event 3 - AJP lab on 3rd Sept. 1500-1600
    events[2] = eventList.createEvent(); 
    events[2].addDate(Event.START, PIMItem.ATTR_NONE, 1346684400000L / 10);
    events[2].addDate(Event.END, PIMItem.ATTR_NONE, 1346688000000L / 10);
    events[2].addString(Event.LOCATION, PIMItem.ATTR_NONE, "IT1.08");
    events[2].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Advanced Java Programming Labs");
    events[2].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PUBLIC);
    events[2].addString(Event.NOTE, PIMItem.ATTR_NONE, "Remember to check lab software version!");

    // Event 4 - Secret job interview, shhhhh
    events[3] = eventList.createEvent(); 
    events[3].addDate(Event.START, PIMItem.ATTR_NONE, 1346752800000L / 10);
    events[3].addDate(Event.END, PIMItem.ATTR_NONE,  1346760000000L / 10);
    events[3].addString(Event.LOCATION, PIMItem.ATTR_NONE, "Reading");
    events[3].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Job interview with rival university");
    events[3].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_CONFIDENTIAL);

    // Event 5 - AJP lecture Sept. 5 11-12
    events[4] = eventList.createEvent(); 
    events[4].addDate(Event.START, PIMItem.ATTR_NONE,  1346842800000L/ 10);
    events[4].addDate(Event.END, PIMItem.ATTR_NONE,  1346846400000L / 10);
    events[4].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Advanced Java Programming lecture");
    events[4].addString(Event.LOCATION, PIMItem.ATTR_NONE, "OL7");
    events[4].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PUBLIC);

    // Event 6 - Project meeting, clashes with event 5
    events[5] = eventList.createEvent(); 
    events[5].addDate(Event.START, PIMItem.ATTR_NONE,  1346842800000L/ 10);
    events[5].addDate(Event.END, PIMItem.ATTR_NONE,  1346846400000L / 10);
    events[5].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Project meeting");
    events[5].addString(Event.LOCATION, PIMItem.ATTR_NONE, "G0.44A");
    events[5].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PUBLIC);
    events[5].addString(Event.NOTE, PIMItem.ATTR_NONE, "Student name is Will G. Rumble. Subject formal methods.");

    // Event 7 - Visit to cinema Sept. 5 1800-2100
    events[6] = eventList.createEvent(); 
    events[6].addDate(Event.START, PIMItem.ATTR_NONE, 1346868000000L / 10);
    events[6].addDate(Event.END, PIMItem.ATTR_NONE,  1346878800000L / 10);
    events[6].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Watch Dredd 3D");
    events[6].addString(Event.LOCATION, PIMItem.ATTR_NONE, "Teesside retail park");
    events[6].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PRIVATE);

    // Event 8 - Project meeting 7th Sept. 0930-1000
    events[7] = eventList.createEvent(); 
    events[7].addDate(Event.START, PIMItem.ATTR_NONE, 1347010200000L /  10);
    events[7].addDate(Event.END, PIMItem.ATTR_NONE,   1347012000000L / 10);
    events[7].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Project meeting");
    events[7].addString(Event.LOCATION, PIMItem.ATTR_NONE, "G0.44A");
    events[7].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PUBLIC);
    events[7].addString(Event.NOTE, PIMItem.ATTR_NONE, "Student name is Peter Out Subject fractal computing.");

    // Event 9 - Project meeting 7th Sept. 1030-1100
    events[8] = eventList.createEvent(); 
    events[8].addDate(Event.START, PIMItem.ATTR_NONE, 1347013800000L /  10);
    events[8].addDate(Event.END, PIMItem.ATTR_NONE,   1347015600000L / 10);
    events[8].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Project meeting");
    events[8].addString(Event.LOCATION, PIMItem.ATTR_NONE, "G0.44A");
    events[8].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PUBLIC);
    events[8].addString(Event.NOTE, PIMItem.ATTR_NONE, "Student name is Ivor Problem. Subject formal methods.");

    // Event 10 - PMD lab 7th Sept. 1600-1700
    events[9] = eventList.createEvent(); 
    events[9].addDate(Event.START, PIMItem.ATTR_NONE, 1347033600000L /  10);
    events[9].addDate(Event.END, PIMItem.ATTR_NONE,   1347037200000L / 10);
    events[9].addString(Event.SUMMARY, PIMItem.ATTR_NONE, "Programming for Mobile Devices labs");
    events[9].addString(Event.LOCATION, PIMItem.ATTR_NONE, "OL7");
    events[9].addInt(Event.CLASS, PIMItem.ATTR_NONE, Event.CLASS_PUBLIC);

    try 
    {
        // Commit events to database
        for(int i=0; i < events.length; i++)
        {
            events[i].commit();
        }
    } catch (PIMException e) 
    {
        System.err.println("Cannot commit the events to database");
        return;
    }

    try 
    {
        eventList.close();
    } catch (PIMException e) 
    {
        System.err.println("Cannot close the database");
        return;
    }
    System.out.println("Events have been added to calendar.....");




    }
}

请注意,我的日历基于以下链接中的示例。
Java ME 日历不显示

4

0 回答 0