Class MenuGame.java
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
* @author evo
*/
public class MenuGame extends Canvas implements Runnable {
private Midlet midlet;
private Image bg;
private Image subMenuOn[] = new Image[4]; //deklarasi submenu on
private Image subMenuOff[] = new Image[4]; //deklarasi submenu off
private int currentPOs;
public MenuGame(Midlet m){
this.midlet = m;
setFullScreenMode(true);
try {
bg = Image.createImage("/gambar/bg_menu.gif");
for (int i = 0; i<4; i++) {
subMenuOn [i] = Image.createImage("/gambar/images_on_" + i + ".png");
subMenuOff [i] = Image.createImage("/gambar/images_off_" + i + ".png");
}
} catch (IOException ex) {
ex.printStackTrace();
}
new Thread(this).start();
}
protected void keyReleased(int keyCode){
System.out.println("kode tombol sekarang : " + keyCode); //Mecari Kode TOmbol di HP
if((keyCode==50 || keyCode==-1) && currentPOs !=0){
currentPOs--;
} else if((keyCode==56 || keyCode==-2) && currentPOs !=3){
currentPOs++;
}
if ((keyCode==53 || keyCode==-5) && currentPOs==3) // Untuk Link Menu Keluar
midlet.destroyApp(true);
if ((keyCode==53 || keyCode==-5) && currentPOs==0) // Untuk Link Menu Mulai
midlet.d.setCurrent(midlet.l1);
}
public MenuGame() {
}
protected void paint(Graphics g) {
g.drawImage(bg, 0, 0, 0);
for(int i=0; i< 4; i ++){
if(currentPOs==i) {
g.drawImage(subMenuOff[i], 50, i * 50 + 80, 0);
} else {
g.drawImage(subMenuOn[i], 50, i * 50 + 80, 0);
}
}
}
public void run() {
while (true) {
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
Tidak ada komentar:
Posting Komentar