Wednesday, November 18, 2009

To Demonstrate Dialog Box

PROBLEM STATEMENT
Write an application to demonstrate a dialog box.

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

public class practical6 extends MIDlet implements CommandListener
{
Form form1;
Display display;
Command save;
public TextField tfname,tfoc,tfcolor,tfgame;
String s="Saving Data...........";
Alert al;
public practical6()
{
try
{
// Indicating the object to be Displayed
display=Display.getDisplay(this);

//initializing Form’s object
form1=new Form("");

//Initailizing save Command button
save=new Command("SAVE",Command.ITEM,1);

//Initailizing TextField’s objects.
tfname=new TextField
("Enter Name:","",15,TextField.ANY);

tfoc=new TextField("Enter OCCUPATION","",20,TextField.ANY);

tfcolor=new TextField("Enter Favourite Color","",8,TextField.ANY);

tfgame=new TextField("Enter Favourite Game","",10,TextField.ANY);

//Adding TextFeilds and Commands to from1

form1.append(tfname);
form1.append(tfoc);
form1.append(tfcolor);
form1.append(tfgame);
form1.addCommand(save);

//Initailizing Image object.

Image im = Image.createImage("/p2.gif");

//Initailizing Alert object for image saving Conformation.

al=new Alert("New Alert", " Saving Data...........", im, AlertType.CONFIRMATION);

// Adding Command Listner

form1.setCommandListener(this);
}
catch(Exception e)
{

// message is displayed if the error occurs while reading the file .

System.out.println("Unable to read png image.");
}
}

public void startApp()
{

// Indicating the object to be Displayed

display.setCurrent(form1);

}
public void pauseApp(){}

public void destroyApp(boolean Unconditional)
{
// Indicating the object to be Displayed

destroyApp(false);
notifyDestroyed();
}
public void endp()
{
// Indicating the object to be Displayed

destroyApp(false);
notifyDestroyed();
}

public void commandAction(Command c, Displayable d)
{
if(c==save)
{
display.setCurrent(al, form1);
al.setTimeout(Alert.FOREVER);

}

}
}

No comments:

Post a Comment