📄 imageloadermidlet.java
字号:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ImageLoaderMIDlet extends MIDlet {
private Item mItem;//联机成功时作为ImageItem,失败时作为StringItem
public void startApp() {
final Display display = Display.getDisplay(this);
if (mItem == null) {
Form mainForm = new Form("载入中...");
display.setCurrent(mainForm);
// Create the Form that will show the Image.
final Form imageForm = new Form("图片");
imageForm.addCommand(new Command("离开", Command.EXIT, 0));
imageForm.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable s) {
notifyDestroyed();
}
});
// Do network loading in a separate thread.
Thread t = new Thread() {
public void run() {
try {
String URL = "http://localhost/JIDCA/Duke.png";
Image image = loadImage(URL);
mItem = new ImageItem(null, image, 0, null);
}
catch (IOException ioe) {
mItem = new StringItem(null, ioe.toString());
}
imageForm.append(mItem);
display.setCurrent(imageForm);
}
};
t.start();
}
}
public Image loadImage(String url) throws IOException {
HttpConnection hpc = null;
DataInputStream dis = null;
try {
hpc = (HttpConnection)Connector.open(url);
int length = (int)hpc.getLength();
byte[] data = new byte[length];
dis = new DataInputStream(hpc.openInputStream());
dis.readFully(data);
return Image.createImage(data, 0, data.length);
}
finally {
if(hpc != null) hpc.close();
if(dis != null) dis.close();
}
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -