You are on page 1of 4

Menu.

java
import javax.microedition.lcdui.*;

CanvasSatu.java
import javax.microedition.lcdui.*; class CanvasSatu extends Canvas{ public void paint(Graphics g){ g.setColor(255,0,0); g.fillRect(0,0,getWidth(),getHeight()); g.setColor(255,255,255); g.fillRect(getWidth()/2,getHeight()/2,getWidth(),getHeight()); g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_LARGE)); g.drawString("STMIK",getWidth(),0,Graphics.RIGHT|Graphics.TOP); g.drawRect(8, 8, 64, 32); g.drawString("STMIK",15,15,Graphics.LEFT|Graphics.TOP); } }

CanvasDua.java
import javax.microedition.lcdui.*; class CanvasDua extends Canvas{ private String gameAction = "[Tekan Tombol]"; private int x=34, y=47; public void paint(Graphics g){ g.setColor(200,200,200); g.fillRect(0,0,getWidth(),getHeight());

try { //drawImage(Image img, int x, int y, int anchor) //Baris Pertama Image image0 = Image.createImage("/icon/1.png"); g.setColor(255,255,255); g.fillRect(x,y,image0.getWidth()+4,image0.getHeight()+4);

g.drawImage(image0,(25*getWidth())/100,(25*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); Image image1 = Image.createImage("/icon/2.png"); g.drawImage(image1,(50*getWidth())/100,(25*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); Image image2 = Image.createImage("/icon/3.png"); g.drawImage(image2,(75*getWidth())/100,(25*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); //Baris Kedua Image image4 = Image.createImage("/icon/5.png"); g.drawImage(image4,(25*getWidth())/100,(50*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); Image image5 = Image.createImage("/icon/6.png"); g.drawImage(image5,(50*getWidth())/100,(50*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); Image image6 = Image.createImage("/icon/7.png"); g.drawImage(image6,(75*getWidth())/100,(50*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); //Baris Ketiga Image image8 = Image.createImage("/icon/9.png"); g.drawImage(image8,(25*getWidth())/100,(75*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); Image image9 = Image.createImage("/icon/10.png"); g.drawImage(image9,(50*getWidth())/100,(75*getHeight())/100,Graphics.VCENTER|Graphics.H CENTER); Image image10 = Image.createImage("/icon/11.png"); g.drawImage(image10,(75*getWidth())/100,(75*getHeight())/100,Graphics.VCENTER|Graphics. HCENTER);

} catch (Exception e){} } protected void keyPressed(int keyCode) { switch(getGameAction(keyCode)) { case UP: if(y<(25*getHeight()/100)){ y = y + (50*getHeight())/100;} else{ y = y - (25*getHeight())/100;} break; 2

case DOWN: if(y>(50*getHeight()/100)){ y = (25*getHeight())/100 - 25 ;} else{ y = y + (25*getHeight())/100;} break; case LEFT: if(x<(25*getWidth())/100){ x=x+(50*getWidth())/100; y = y + (50*getHeight())/100; } else{ x = x - (25*getWidth())/100;} break; case RIGHT: if(x>(50*getWidth())/100){ x=(25*getWidth())/100 - 25; y = y + (25*getHeight())/100;} else if(x>(50*getWidth())/100 || y>(75*getHeight()/100)){ y = (25*getHeight())/100 - 25 ; x = (25*getWidth())/100 - 25;} else{ x = x + (25*getWidth())/100;} break; case FIRE: x=x;y=y; break;

//default: } repaint(); } }

gameAction = "";

break;

ContohCancas.java
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ContohCanvas extends MIDlet { //deklarasi Display dis; CanvasSatu canvas; CanvasDua canvas2; //cunstruktor public ContohCanvas(){ canvas = new CanvasSatu(); canvas2 = new CanvasDua(); } //methode public void startApp() { dis = Display.getDisplay(this); dis.setCurrent(canvas2); }

public void pauseApp() { } public void destroyApp(boolean unconditional) { } }