Monday, December 10, 2012
Menggambar teks di atas canvas pada JAVA (J2ME)
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class GambarTeks extends MIDlet
implements CommandListener {
private Display display;
private TextCanvas canvas;
private final Command cmdKeluar =
new Command("Keluar", Command.EXIT, 1);
public GambarTeks() {
display = Display.getDisplay(this);
canvas = new TextCanvas(this);
canvas.addCommand(cmdKeluar);
canvas.setCommandListener(this);
}
public void startApp() {
display.setCurrent(canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
notifyDestroyed();
}
}
class TextCanvas extends Canvas {
private GambarTeks midlet;
public TextCanvas(GambarTeks midlet) {
this.midlet = midlet;
}
public void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255, 0, 0);
Font font = Font.getFont(Font.FACE_PROPORTIONAL,
Font.STYLE_BOLD | Font.STYLE_UNDERLINED,
Font.SIZE_MEDIUM);
g.setFont(font);
g.drawString("Teks di dalam Canvas", 0, 0, g.LEFT | g.TOP);
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment