Crea sito

//SampleMidlet.java

//Sample midlet program that could be converted to PRC files

//that install into a Palm PDA.

import javax.microedition.lcdui.*;

import javax.microedition.midlet.*;

import javax.microedition.io.*;

import java.io.* ;

import java.lang.*;

public class SampleMidlet extends MIDlet implements

CommandListener

{

//member variables

private Display dCurrentDisplay;

private Form mMainMenu;

private List lChooselist;

private Ticker tMainTicker;

private TextBox txtInputBox;

private DateField dDate = new DateField("Today : ",

DateField.DATE);

//commands used, such as button, labels, and screens

static final Command cBack =

new Command("Back",Command.BACK,0); //back button

static final Command cExit =

new Command("Exit",Command.STOP,2); //Exit button

static final Command cTransfer =

new Command ("Transfer",Command.SCREEN,3);

//variables

String CurrentMenu = null;

String Text = null;

//constructors

public SampleMidlet()

{

mMainMenu = new Form("");

tMainTicker = new Ticker("Ciao, sono io!");

}

//-----------------------------------------------------------

//start application method -- called initailly while running

public void startApp() throws MIDletStateChangeException

{

dCurrentDisplay = Display.getDisplay(this);

lChooselist = new List("",Choice.IMPLICIT);

lChooselist.append("Saluta",null);

lChooselist.append("leggi",null);

lChooselist.append("scrivi",null);

lChooselist.addCommand(cExit);

lChooselist.setCommandListener(this);

lChooselist.setTicker(tMainTicker);

mainmenu();

}

//-----------------------------------------------------------

//mainmenu method to display the option list

void mainmenu()

{

dCurrentDisplay.setCurrent(lChooselist);

CurrentMenu = "Main";

}

//-----------------------------------------------------------

//PauseApp method to stop the program

public void pauseApp()

{

dCurrentDisplay = null;

lChooselist = null;

tMainTicker = null;

mMainMenu = null;

txtInputBox =null;

}

//-----------------------------------------------------------

public void ShowHello()

{

txtInputBox = new TextBox(" ","",50,TextField.ANY);

txtInputBox.addCommand(cBack);

txtInputBox.setCommandListener(this);

txtInputBox.setString("Uelaaaaa'");

dCurrentDisplay.setCurrent(txtInputBox);

CurrentMenu = "Hello";

}

//-----------------------------------------------------------

public void GetInput()

{

txtInputBox = new TextBox("Scrivi:","",50,TextField.ANY);

txtInputBox.addCommand(cBack);

txtInputBox.setCommandListener(this);

txtInputBox.setString(" ");

dCurrentDisplay.setCurrent(txtInputBox);

CurrentMenu = "Input";

}

//-----------------------------------------------------------

public void PrintInput()

{

txtInputBox = new TextBox("Hai scritto:",

"",50,TextField.ANY);

txtInputBox.addCommand(cBack);

txtInputBox.setCommandListener(this);

txtInputBox.setString(Text);

dCurrentDisplay.setCurrent(txtInputBox);

CurrentMenu = "Print";

}

//-----------------------------------------------------------

public void destroyApp(boolean unconditional)

{

notifyDestroyed();

}

//-----------------------------------------------------------

//Handle List Events

public void commandAction(Command c, Displayable d)

{

String sLabel = c.getLabel();

if(sLabel.equals("Exit"))

{

destroyApp(true);

}

else if(sLabel.equals("Back"))

{

if(CurrentMenu.equals("Input"))

{

Text = txtInputBox.getString();

mainmenu();

}

if(CurrentMenu.equals("Hello"))

mainmenu();

if(CurrentMenu.equals("Print"))

mainmenu();

}

else

{

List nIndex = (List)dCurrentDisplay.getCurrent();

switch(nIndex.getSelectedIndex())

{

case 0:ShowHello();

break;

case 1:GetInput();

break;

case 2:PrintInput();

break;

default:break;

}

}

}

//-----------------------------------------------------------

} //end program