Monday, December 10, 2012
Mengatur posisi gambar yang ditampilkan, pada JAVA (J2ME)
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class AturLayoutGambar extends MIDlet
implements CommandListener {
private Display display;
private List list;
private PosisiGambar form;
private String title = null;
private final Command cmdKeluar =
new Command("Keluar", Command.EXIT, 1);
private final Command cmdOK =
new Command("OK", Command.OK, 1);
public AturLayoutGambar() {
display = Display.getDisplay(this);
list = new List("Posisi Gambar", Choice.EXCLUSIVE);
list.append("Kiri", null);
list.append("Tengah", null);
list.append("Kanan", null);
list.addCommand(cmdKeluar);
list.addCommand(cmdOK);
list.setCommandListener(this);
}
public void startApp() {
display.setCurrent(list);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
notifyDestroyed();
} else if (c == cmdOK) {
form = null;
switch (list.getSelectedIndex()) {
case 0: {
form = new PosisiGambar(this, display,"LAYOUT_LEFT",
ImageItem.LAYOUT_LEFT);
break;
}
case 1: {
form = new PosisiGambar(this, display,"LAYOUT_CENTER",
ImageItem.LAYOUT_CENTER);
break;
}
case 2: {
form = new PosisiGambar(this, display,"LAYOUT_RIGHT",
ImageItem.LAYOUT_RIGHT);
break;
}
}
display.setCurrent(form);
}
}
class PosisiGambar extends Form
implements CommandListener {
private AturLayoutGambar midlet;
private Display display;
private Image image;
private final Command cmdKembali =
new Command("Kembali", Command.BACK, 1);
public PosisiGambar(StudiKasus midlet, Display display,
String title, int posisi) {
super(title);
this.midlet = midlet;
this.display = display;
image = null;
try {
image = Image.createImage("Java.png");
} catch (IOException ioe) {
ioe.printStackTrace();
}
ImageItem ii = new ImageItem(null, image, posisi, null);
append(ii);
addCommand(cmdKembali);
setCommandListener(this);
display.setCurrent(this);
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKembali) {
display.setCurrent(midlet.list);
}
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment