Wednesday, November 18, 2009

To demonstrate different “INPUT BOXES”

PROBLEM STATEMENT
Write a program in J2ME to demonstrate different input boxes.
1.Edit Box(Text Box)
2.Buttons
3.Radio Buttons
4.Check Box
5.List Box.

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

public class Practical3 extends MIDlet implements CommandListener
{
private Command exit,next;
private TextField tb1;
private Form frm1;
private Display display;
private ChoiceGroup rb;
private ChoiceGroup cb;
private List list;
private Alert alert;
private String[] options={"Option A","Option B"};

public Practical3()
{
next=new Command("NEXT",Command.SCREEN,0);
exit=new Command("Exit",Command.SCREEN,0);

frm1=new Form("Practical3");

tb1=new TextField("Enter Name","",30,TextField.ANY);

rb=new ChoiceGroup("Option",Choice.EXCLUSIVE);
rb.append("Male",null);
rb.append("Female",null);

cb=new ChoiceGroup("Option",Choice.MULTIPLE);
cb.append("Red",null);
cb.append("Green",null);

list=new List("Menu:",List.IMPLICIT,options,null);
list.addCommand(next);
list.setCommandListener(this);

frm1.append(tb1);
frm1.append(rb);
frm1.append(cb);

frm1.addCommand(exit);
frm1.setCommandListener(this);


public void startApp()
{
display=Display.getDisplay(this);
display.setCurrent(list);
}

public void pauseApp(){ }

public void destroyApp(boolean b){ }

public void commandAction(Command c,Displayable d)
{
if(c==next)
{
alert=new Alert("Next Form","Moving To Next Form",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert,frm1);
}

if(c==exit)
{
destroyApp(true);
notifyDestroyed();
}
}
}

No comments:

Post a Comment