Anda di halaman 1dari 10

August 14, 2012

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

Memabuat Splash dan Menu Game J2ME Netbeans Kali ini saya akan memberikan sedikit tutorial bagaimana membuat Splash dan Menu Game Menggunakan Netbeans, berikut ini langkah langkahnya :D 1. Siapkan Gambar Splash anda dan contoh Menu yang anda inginkan misalnya seperti gambar di bawah ini:

Gambar Splash

August 14, 2012

Gambar Menu

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

2. Buatlah Project baru di Netbeans Anda :D

Gambar New Project

August 14, 2012

Gambar New Mobile Aplicatioan

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

Gambar Membuat Package Baru

August 14, 2012

Gambar Membuat Package Baru

3. Selanjutnya Copy gambar Splash dan Menu Anda Tadi ke package yang baru anda buat :D

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

Gambar Copy Splash dan Menu

4. Buat lagi Package baru seperti diatas dengan nama splashku :D

Gambar Membuat Package Baru

August 14, 2012

5. Membuat Class Java di dalam Package splashku dengan nama Splash dan Menu :D

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

Gambar Membuat Class Java Baru

Gambar Nama Class Baru

August 14, 2012

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

6. Selanjutnya Ketik Codding berikut ini atau di Copas Aja :D

package Splashku; import java.io.IOException; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; public class Splash extends Canvas{ private Image splash; public Splash() { setFullScreenMode(true); try { splash = Image.createImage("/menu/splash.png"); } catch (IOException ex) { ex.printStackTrace(); } } protected void paint(Graphics g) { g.drawImage(splash, 0, 0, 0); } }

7. Kemudian pada Class Menu yang di buat tadi Copas Juga Kode ini :D
package Splashku; mport java.io.IOException; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.game.GameCanvas; public class Menu extends Canvas implements Runnable{ private Image menu; private Image subMenuOn[] = new Image[4]; private Image subMenuOff[] = new Image[4]; Midlet midlet; int currentpost; Display d; public Menu(Midlet m, Display d) { this.midlet = m; this.d = d; setFullScreenMode(true); try { menu = Image.createImage("/menu/bg_menu.png"); for(int i=0;i<4;i++) { subMenuOn[i] Image.createImage("/menu/images_on_"+i+".png");

August 14, 2012

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

subMenuOff[i] Image.createImage("/menu/images_off_"+i+".png"); } } catch (IOException ex) { ex.printStackTrace(); } new Thread(this).start(); } protected void paint(Graphics g) { g.drawImage(menu, 0, 0, 0); for(int i=0;i<4;i++) { if(currentpost==i) { g.drawImage(subMenuOn[i], 40, i*55+80, 0); } else { g.drawImage(subMenuOff[i], 40, i*55+80, 0); } } } protected void keyReleased(int keyCode) { System.out.println("Nilai Tombol : "+keyCode); if((keyCode==-1 || keyCode==50)&&(currentpost!=0)) { currentpost--; } else if((keyCode==-2|| keyCode==56)&&(currentpost!=3)) { currentpost++; } else if((keyCode==-5|| keyCode==53)&&(currentpost==3)) { midlet.destroyApp(true); } } public void run() { while(true) { repaint(); try { Thread.sleep(20); } catch (InterruptedException ex) { ex.printStackTrace(); } } } }

August 14, 2012

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

8. Yang terakhir Buat Class Midlet :D

Gambar Membuat Class Midlet

Gambar New Midlet

9. Jika Sudah Tinggal Copas Code Berikut Ini :D


package Splashku; import javax.microedition.lcdui.Display; import javax.microedition.midlet.*; public class Midlet extends MIDlet { private Display d; private Splash s; private Menu m; public void startApp() { d = Display.getDisplay(this);

August 14, 2012

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com

splash(); menu(); d.setCurrent(s); try { Thread.sleep(2000); } catch (InterruptedException ex) { ex.printStackTrace(); } d.setCurrent(m); } public void splash () { s = new Splash(); } public void menu () { m = new Menu(this, d); d.setCurrent(m); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }

10. Coba Di Running maka Hasilnya Sebagai Berikut :D

August 14, 2012

Gambar Splah

Gambar Menu

AHMAD SUBKI >> Contact >> www.pelajar-mania.blogspot.com