Java Reference
In-Depth Information
The first parameter is named “pOne” and has “one bit” as a value; the second parameter is
named “pTwo” and has “two” as a value.
A Simple Example
HTTP isn't all about exchanging HTML pages. It's actually a generic file-exchange protocol.
In this section, we'll look at an example that loads an image from the network and displays it.
Listing 10-1 shows the source code for ImageLoader , a MIDlet that retrieves an image from the
Internet and displays it on the screen.
Listing 10-1. Retrieving an Image from the Internet
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ImageLoader
extends MIDlet
implements CommandListener, Runnable {
private Display mDisplay;
private Form mForm;
public ImageLoader() {
mForm = new Form("Connecting...");
mForm.addCommand(new Command("Exit", Command.EXIT, 0));
mForm.setCommandListener(this);
}
public void startApp() {
if (mDisplay == null) mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mForm);
// Do network loading in a separate thread.
Thread t = new Thread(this);
t.start();
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT)
notifyDestroyed();
}
Search WWH ::




Custom Search