www.pudn.com > resources.zip > Hello.java
package net.frog_parrot.hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* This is the main class of the hello world demo.
*
* @author Carol Hamer
*/
public class Hello extends MIDlet implements CommandListener {
Display myDisplay;
HelloCanvas myCanvas;
private Command exitCommand = new Command("Exit", Command.EXIT, 99);
private Command newCommand = new Command("Toggle Msg", Command.SCREEN, 1);
/**
* Initialize the canvas and the commands.
*/
public Hello() {
myDisplay = Display.getDisplay(this);
myCanvas = new HelloCanvas(myDisplay);
myCanvas.addCommand(exitCommand);
myCanvas.addCommand(newCommand);
myCanvas.setCommandListener(this);
}
//----------------------------------------------------------------
// implementation of MIDlet
/**
* Start the application.
*/
public void startApp() throws MIDletStateChangeException {
myCanvas.start();
}
/**
* Does nothing.
*/
public void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}
/**
* Does nothing.
*/
public void pauseApp() {
}
//----------------------------------------------------------------
// implementation of CommandListener
/*
* Respond to a command issued on the Canvas.
* (either reset or exit).
*/
public void commandAction(Command c, Displayable s) {
if(c == newCommand) {
myCanvas.newHello();
} else if(c == exitCommand) {
try {
destroyApp(false);
notifyDestroyed();
} catch (MIDletStateChangeException ex) {
}
}
}
}