Hello Canvas


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Hello extends MIDlet {
public Hello() {
}
public void startApp() {
Canvas canvas = new MyCanvas();
Display display = Display.getDisplay(this);
display.setCurrent(canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class MyCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255, 0, 0);
g.drawLine((getWidth()/2),0,0, (getHeight()/2));
g.drawLine(0, (getHeight()/2), (getWidth()/2),getHeight());
g.drawLine((getWidth()/2),getHeight(), (getWidth()),(getHeight()/2));
g.drawLine((getWidth()),(getHeight()/2), (getWidth()/2),0) ;
g.setColor(255, 0, 0);
g.fillRect((getWidth()/2)-50, (getHeight()/2)-50, 100, 100);
g.setColor(255, 255, 255);
g.drawString(“Hello World!”, (getWidth()/2)-30, (getHeight()/2)-10, g.TOP | g.LEFT);
}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s