Signed MIDlets - SignedMIDlet

The following is the source for the SignedMIDlet class.

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class SignedMIDlet
  extends MIDlet
  implements Runnable, CommandListener

  private final TextField text 
    = new TextField("", "", 256, TextField.ANY);
  private final Form form = new Form("HTTP Result");
  private final Command exitCommand 
    = new Command("Exit", Command.EXIT, 1);
  private final Command okCommand = new Command("Load", Command.OK, 1);

  public SignedMIDlet() {}

  public void startApp()
  {
    if (Display.getDisplay(this).getCurrent()==null)

      form.setCommandListener(this);
      form.addCommand(exitCommand);
      form.addCommand(okCommand);
      form.append(text);
      Display.getDisplay(this).setCurrent(form);
    }
  }

  public void pauseApp() {}

  public void destroyApp(boolean unconditional) {}

  public void run()
  {
    // do an action that requires permission, e.g. HTTP connection
    try
    {
      String url = getAppProperty("url");
      HttpConnection connection =
(HttpConnection) Connector.open(url);
      InputStream in = connection.openInputStream();
      int counter = 0;
      int ch;
      while ((ch = in.read()) != -1)
      {
        counter++;
      }
      in.close();
      connection.close();
      text.setString("Bytes read: " + counter);
    }
    catch (IOException e)
    {
      text.setString("IOException: " + e.getMessage());
    }
    catch (SecurityException e)
    {
      text.setString("SecurityException: " + e.getMessage());
    }
  }

  public void commandAction(Command command, Displayable displayable)
  {
    if (command == exitCommand)
    {
      notifyDestroyed();
    }
    else if (command == okCommand)
    {
      new Thread(this).start();
    }
  }