Tuesday, September 14, 2010

mc lab manual 3rd expt

Experiment No. 3

Experiment Name: MIDlet to display Current Date and Time.

Resources Required:

a . Equipments/Machines:

PIII 810 MHz, 20 GB HDD, 128 MB RAM, 1.44 FDD

14” color Monitor, 101 Keyboard, Serial mouse, LAN card

Dot matrix printer.

S/W : Sun Java Wireless Toolkit , Java

b . Consumables: Printer pages for printouts.

Theory:

Each MIDlet must extend the abstract MIDlet class found in the javax.microedition.midlet package, much like creating an applet by extending the java.applet.Applet class. At the minimum, your MIDlet must override three methods of this abstract class, startApp(), pauseApp(), and destroyApp(boolean unconditional).

In this example, DateTimeApp's constructor creates the element that is necessary to display the time on a device's screen and the startApp method does the actual task of displaying this element.

Copy this code into a file called DateTimeApp.java and save it in a folder that mimics its package structure (com\j2me\part1). You can save it anywhere you want on your machine; as far as this article is concerned, we will save it in the folder C:\WTK22\article\com\j2me\part1.

For the example application, our Date-Time MIDlet does not need user interactivity. It needs to display the current date and time for a few seconds when the user executes the MIDlet

Code For DateTimeApp.java :

package com.j2me.part1;

import java.util.Date;

import javax.microedition.lcdui.Alert;

import javax.microedition.lcdui.Display;

import javax.microedition.midlet.MIDlet;

public class DateTimeApp extends MIDlet {

Alert timeAlert;

public DateTimeApp() {

timeAlert = new Alert("Alert!");

timeAlert.setString(new Date().toString());

}

public void startApp() {

Display.getDisplay(this).setCurrent(timeAlert);

}

public void pauseApp() {

}

public void destroyApp(boolean unconditional) {

}

}


Conclusion : Thus we have successfully created MIDlet for displaying Current Date and Time.

No comments:

 

Free HTML Hit Counters

Locations of visitors to this page