import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
public class StringImageMIDlet extends MIDlet
implements CommandListener {
private Display display;
private Form form;
private StringItem si = null;
private ImageItem ii = null;
private final Command cmdKeluar = new Command("Keluar",
Command.EXIT, 1);
public StringImageMIDlet() {
display = Display.getDisplay(this);
}
public void startApp() {
form = new Form("StringItem dan ImageItem");
// membuat instance dari kelas StringItem
si = new StringItem(null, "Gambar Java", Item.PLAIN);
si.setFont(Font.getFont(Font.FACE_MONOSPACE,
Font.STYLE_ITALIC | Font.STYLE_UNDERLINED,
Font.SIZE_MEDIUM));
// membuat gambar yang akan dimasukkan ke objek ImageItem
Image image = null;
try {
image = Image.createImage("/Java.png");
} catch (IOException ioe) {
ioe.printStackTrace();
}
// membuat instance dari kelas ImageItem
ii = new ImageItem(null, image,
Item.LAYOUT_NEWLINE_BEFORE, null);
form.append(si);
form.append(ii);
form.addCommand(cmdKeluar);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
}
}
}
No comments:
Post a Comment