public void commandAction(Command cmd, Displayable disp)
{
if (cmd == connCommand)
{
synchronized (this)
{
notify();
}
} else if (cmd == exitCommand)
{
exitMIDlet();
}
}
private void exitMIDlet()
{
try
{
destroyApp(false);
notifyDestroyed();
} catch (MIDletStateChangeException e)
{
e.printStackTrace();
}
}
class GetterThread extends Thread
{
private ImageGetter midlet;
public static final String URL = "http://localhost/j2medev.png";
private HttpConnection httpConn = null;
private InputStream is = null;
public GetterThread(ImageGetter midlet)
{
this.midlet = midlet;
}
public void run()
{
synchronized (midlet)
{
try
{
midlet.wait();
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
System.out.println("connect to server...");
try
{
httpConn = (HttpConnection) Connector.open(URL);
is = httpConn.openInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int ch = 0;
while ((ch = is.read()) != -1)
{
baos.write(ch);
}
byte[] imageData = baos.toByteArray();
Image image = Image.createImage(imageData, 0, imageData.l