|
package com.robohobby.me;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
@Ads
@author
public class RobotMIDlet extends MIDlet implements CommandListener {
public boolean midletPaused = false;
CallBacks callBacks = CallBacks.getInstance();
private Command exitCommand;
private Command doHttpRequestCommand;
private Command infoItemCommand;
private Command itemCommand;
private Form form;
private StringItem urlInfoStringItem;
private StringItem resultStringItem;
private StringItem infoStringItem;
public RobotMIDlet() {
callBacks.robotMIDlet = this;
}
<code></code>
private void initialize() {
}
public void startMIDlet() {
switchDisplayable(null, getForm());
}
public void resumeMIDlet() {
}
<code></code> <code></code>
@param
<code></code> <code></code>
@param
public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
}
@param
@param
public void commandAction(Command command, Displayable displayable) {
if (displayable == form) {
if (command == doHttpRequestCommand) {
doHttpRequestCommand();
} else if (command == exitCommand) {
exitMIDlet();
}
}
}
private void doHttpRequestCommand()
{
HttpUtils httpUtils = new HttpUtils();
Thread httpUtilsThread = new Thread( httpUtils );
httpUtilsThread.start();
}
@return
public Command getExitCommand() {
if (exitCommand == null) {
exitCommand = new Command("Exit", Command.EXIT, 0);
}
return exitCommand;
}
@return
public Form getForm() {
if (form == null) {
form = new Form("www.RoboHobby.com", new Item[]
{ getUrlInfoStringItem(), getInfoStringItem(), getResultStringItem() });
form.addCommand(getExitCommand());
form.addCommand(getDoHttpRequestCommand());
form.setCommandListener(this);
}
return form;
}
@return
public StringItem getUrlInfoStringItem() {
if (urlInfoStringItem == null) {
urlInfoStringItem = new StringItem("URL: ", "", Item.PLAIN);
}
return urlInfoStringItem;
}
@return
public Command getDoHttpRequestCommand() {
if (doHttpRequestCommand == null) {
doHttpRequestCommand = new Command("Do HTTP Request", Command.ITEM, 0);
}
return doHttpRequestCommand;
}
@return
public Command getItemCommand() {
if (itemCommand == null) {
itemCommand = new Command("Item", Command.ITEM, 0);
}
return itemCommand;
}
@return
public Command getInfoItemCommand() {
if (infoItemCommand == null) {
infoItemCommand = new Command("State: ", Command.ITEM, 0);
}
return infoItemCommand;
}
@return
public StringItem getResultStringItem() {
if (resultStringItem == null) {
resultStringItem = new StringItem("Result: ", "");
}
return resultStringItem;
}
@return
public StringItem getInfoStringItem() {
if (infoStringItem == null) {
infoStringItem = new StringItem("Info:", "");
}
return infoStringItem;
}
@return
public Display getDisplay () {
return Display.getDisplay(this);
}
public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}
public void startApp() {
if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();
}
midletPaused = false;
}
public void pauseApp() {
midletPaused = true;
}
@param
public void destroyApp(boolean unconditional) {
}
}
| |