Java Programing laungage

J2ME Projects

J2ME Project 1

Creating a J2ME Application for addAlert into Form
Previous Home Next

AlertAn Alert is the dialog box displayed by your program to warn and show data to the user. It is generally used to inform the user about potential errors and other exceptional conditions such as interrupt, beak in communication and waits for a certain period of time before proceeding to the next Displayable. An alert may contain a text string and an image.

addAlert into Form

Alert alert= new Alert(title, alertText, alertImage, alertType)

title = display title of dialog box.

alertText = display text with contain information about alert

alertImage = display image with alert message into dialog box

alertType = user define what type of alert he required in program. Alert Type are - AlertType.ALARM, AlertType.CONFIRMATION, AlertType.ERROR, AlertType.INFO, AlertType.WARNING

Alert Program


/*
 * Save as a addAlert.java
 */
package r4r.Mobile.Basic;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

/**
 * @author R4R
 */
public class addAlert extends MIDlet implements CommandListener {

    /* -- private field -- */
    private Form form;
    private Display display;
    private Alert alert;
    private Command exit, launch;

    /* -- Default constructor -- */
    public addAlert() {
        display = Display.getDisplay(this);
        form = new Form("Add Alert into form");
        exit = new Command("EXIT", Command.EXIT, 1);
        launch = new Command("LAUNCH", Command.OK, 1);
        form.addCommand(exit);
        form.addCommand(launch);
        form.setCommandListener(this);
    }

    public void startApp() {
        // Request to MIDlet for setting the current Displayable object be made visible on the display.
        display.setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == exit) {
            destroyApp(true);       // invoked MIDlet to terminate state
            notifyDestroyed();      // notify to MIDlet has entered into Destroyed state.
        } else if (c == launch) {
            activateAlert();              //invoked activeAlert() method
            form.removeCommand(launch);  // removes a command from the form

        }
    }

    /* -- call activeAlert() method into commandAction -- */
    private void activateAlert() {
        alert = new Alert(" Error ", " -- Alert Launch for 5000 milliseconds --  ", null, AlertType.ALARM);
        alert.setTimeout(5000);           //Set alert timeOut
        display.setCurrent(alert, form);
    }
}

 

output
Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: