Thursday, March 18, 2010

J2ME - Alert Types - Code example

As discussed in J2ME Alerts example earlier, we can show message boxes to the J2ME application users by using Alerts. You can show text alerts as well as Image alerts. Alerts have different types. Each type of alert has a different icon that visually represents the message being given by the Alert.

Each section blow gives a code chunk that shows a different type of Alert in a J2ME app.

AlertType Alarm

This type of Alert shows an alarm typically based on a pre-defined time when  user needs to be reminded of something. If your program is reminding the user of some time based event, this is the alert to use. The code used for this type of alert is :

            Alert a = new Alert("This is the alert");
            a.setTitle("Alert");
            a.setType(AlertType.ALARM);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a);

And the output will look something like:



AlertType CONFIRMATION
This type of alert is used to confirm something from the user. If you are inquiring or questionging the user in a message, this is the AlertType to be used.

Here's the code to show such an Alert:

            Alert a = new Alert("This is the alert");
            a.setTitle("Alert");
            a.setType(AlertType.CONFIRMATION);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a);

 The output of the code will be similar to the image below:



AlertType ERROR
When you want to communicate about an error that has occured in a J2ME program, use AlertType.ERROR in your code. Here's the code sample:

            Alert a = new Alert("This is the alert");
            a.setTitle("Alert");
            a.setType(AlertType.ERROR);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a);

The output of the above code is shown in the screenshot below:



AlertType INFO
An error that gives some general information to the user, you should use INFO type alert. This can be done by using AlertType.INFO when instantiating the Alert object in your code. Following code is used to show an INFO type alert:

            Alert a = new Alert("This is the alert");
            a.setTitle("Alert");
            a.setType(AlertType.INFO);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a);

And here is the output screenshot of the output of the above code.



AlertType Alarm
As the name suggests, this kind of Alert is used to give warnings to the user in a J2ME app. Use following code for giving such warnings:

            Alert a = new Alert("This is the alert");
            a.setTitle("Alert");
            a.setType(AlertType.WARNING);
            a.setTimeout(Alert.FOREVER);
            display.setCurrent(a);

 The output of the above code is given below:




Please note that above alert types are given standard alert types defined in J2ME. Any phones supporting J2ME MIDP should have these alerts available on device. The type of icon, size, shape and color of the icons on the Alert may be different depending on the implementation of the J2ME alerts on that device, but the basic reason of showing the alerts and the type of icons shown on all devices will give out the same message to the user.


Related J2ME articles:

 

4 comments:

  1. I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing.

    Softgen Infotech is the Best SAP HANA Admin Training in Bangalore located in BTM Layout, Bangalore providing quality training with Realtime Trainers and 100% Job Assistance.

    ReplyDelete