Sunday 9 June 2013

Displaying Messages in Alert using LWUIT for Nokia

Displaying Alert in LWUIT for Nokia

asha mobile application

When using LWUIT we should first add and initialise LWUIT in our project.If you want to know how to add LWUIT and Initialise LWUIT please read our previous post NOKIA MOBILE APPLICATION DEVELOPMENT STAGE 3 first then only you can use the following tutorial.

Alert in LWUIT is somewhat different from Alert in LCUDI.We have Alert class in LCUDI which can be directly used in our project instead of that we have to Dialog Class in LWUIT

To create an Alert in LWUIT:

Dialog alert=new Dialog();
alert.setTitle("Alert Message");

You can also set timeout for each alert message in LWUIT like in LCUDI but the time must in Microsecond format.

To set timeOut for Alert in LWUIT: 

alert.setTimeout(2000);

To display the alert in screen you can use two different ways one is using show() method another one is to use showDialog() method.

show() method:

show(int,int,int,int,boolean) is the syntax for show method in which you have to mention the position of the Alert message and final argument boolean is used to mention whether to include the Title for Alert or not (True for showing Title and False for not showing)

e.g

alert.Show(90,90,10,10,true);

showDialog() method:

ShowDialog() doesn't accept any parameters but when you use the showDialog() method your  alert message will be in centre of screen by default.

e.g

alert.showDialog();

SAMPLE CODE:

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.sun.lwuit.Button;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;


public class TestClass extends MIDlet {

Form f1;
Button b1;
Dialog alert;

public TestClass() {
// TODO Auto-generated constructor stub
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
Display.init(this);
f1=new Form("LWUIT Alert");
b1=new Button("Show Alert");
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
alert=new Dialog();
alert.setTitle("I am a Alert");
alert.setTimeout(2000);
alert.showDialog();
}
});
f1.addComponent(b1);
f1.show();

}


}


The output will resemble the one given below


asha mobile application
 asha mobile application

If you have any doubt please free to ask in comment or you can post in our FB group we are eager to help you https://www.facebook.com/groups/digitalnativedev/



5 comments :

  1. nokia is the branded company mostly user are use for this device for more detail please visit:http://www.stingoperationcamera.info/

    ReplyDelete
  2. Thank you for another essential blog. Where else could anyone get that kind of information in such a complete way of writing? I have a presentation incoming week, and I am on the lookout for such information. Mobile App Maker in Mumbai || Mobile App Maker Company in Mumbai || App Developers in Mumbai || Mobile App Developers in Mumbai || Mobile App Development Companies in Mumbai || Mobile Application Development Companies in Mumbai

    ReplyDelete
  3. Thank you for sharing valuable information. Nice post. I enjoyed reading this post.Hotels in Kumbakonam,Budget Hotels in Kumbakonam

    ReplyDelete
  4. You have done a nice post ,it will help others to know overall concept of Displaying messages.Read my story as Top mobile app development company in India for Mobile App Development services

    ReplyDelete
  5. Your story about this topic is with valuable information ,so i like your work.Uber clone Taxi app Solution

    ReplyDelete