Program Menu J2ME


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Menu extends MIDlet implements CommandListener {
Display display;
Command exitCommand;
Command backCommand;
Command okCommand;
Canvas jeni;
Canvas hello;
Canvas bunga;
Canvas garis;
Canvas segiempat;
Canvas sudut;

List itemMenu;
Ticker ticker;

public Menu() {
display = Display.getDisplay(this);
exitCommand = new Command(“Keluar”, Command.EXIT, 1);
backCommand = new Command(“Kembali”, Command.BACK, 2);
okCommand = new Command(“OK”, Command.OK, 3);

ticker = new Ticker(“..oO Pilih Menu Dibawah ini Oo..”);
itemMenu = new List(null, Choice.IMPLICIT);
itemMenu.append(“Jeni”, null);
itemMenu.append(“Hello Word”, null);
itemMenu.append(“Bunga”, null);
itemMenu.append(“Garis”, null);
itemMenu.append(“Segi Empat”, null);
itemMenu.append(“Sudut”, null);

itemMenu.setCommandListener(this);
itemMenu.addCommand(exitCommand);
itemMenu.setTicker(ticker);
display.setCurrent(itemMenu);
}

public void startApp () {
}

public void destroyApp (boolean unconditional) {
}

public void pauseApp () {
}

public void commandAction(Command c, Displayable s) {
if (c == backCommand) {
display.setCurrent(itemMenu);
} else if (s == itemMenu) {
if (c == List.SELECT_COMMAND) {
// Handle the item sected to be displayed
int i = itemMenu.getSelectedIndex();
switch (i) {
case 0: // Show Sample canvas
ticker = new Ticker(“..oO Tampilan Jeni Oo..”);
jeni = new JeniCanvas();
jeni.addCommand(backCommand);
jeni.setTicker(ticker);
jeni.setCommandListener(this);
display.setCurrent(jeni);
break;
case 1: // Show the form
ticker = new Ticker(“..oO Tampilan Hello Word Oo..”);
hello = new MyCanvas();
hello.addCommand(backCommand);
hello.setTicker(ticker);
hello.setCommandListener(this);
display.setCurrent(hello);
break;
case 2: // Show an alert
ticker = new Ticker(“..oO Tampilan Bunga Oo..”);
bunga = new BungaCanvas();
bunga.addCommand(backCommand);
bunga.setTicker(ticker);
bunga.setCommandListener(this);
display.setCurrent(bunga);
break;
case 3: // Show TextBox
ticker = new Ticker(“..oO Tampilan Garis Oo..”);
garis = new GarisCanvas();
garis.addCommand(backCommand);
garis.setTicker(ticker);
garis.setCommandListener(this);
display.setCurrent(garis);
break;
case 4: // Show Exclusive list
ticker = new Ticker(“..oO Tampilan Segi Empat Oo..”);
segiempat = new SegiempatCanvas();
segiempat.addCommand(backCommand);
segiempat.setTicker(ticker);
segiempat.setCommandListener(this);
display.setCurrent(segiempat);
break;
case 5: // Show Multiple List
ticker = new Ticker(“..oO Tampilan Sudut Oo..”);
sudut = new SudutCanvas();
sudut.addCommand(backCommand);
sudut.setTicker(ticker);
sudut.setCommandListener(this);
display.setCurrent(sudut);
break;
}
} else if (c == exitCommand) {
notifyDestroyed();
}
}
}
}

class JeniCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(255,0,0);
g.drawString(“JENI”,getWidth()/2,getHeight()/2,Graphics.TOP | Graphics.HCENTER );
g.setColor(0,0,255);
Font font = g.getFont();
g.drawString(“JAVA EDUCATION NETWORK INDONESIA”,getWidth()/2,getHeight()/2+font.getHeight() ,Graphics.TOP | Graphics.HCENTER);
}
}

class GarisCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getHeight(),getWidth());
g.setColor(255,0,0);
g.drawLine(0,0,getWidth()-1,getHeight()-1);
g.setColor(0,255,0);
g.drawLine(0,getHeight()/2,getWidth()-1,getHeight()/2);
g.setColor(0,0,255);
g.drawLine(0,getHeight()-1,getWidth()-1,getHeight()-1);
g.setColor(0,0,0);
g.drawLine(0,getHeight()-1,getWidth()-1,0);
}
}

class MyCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255, 0, 0);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(255, 255, 255);
g.drawString(“Hello World!”, 0, 0, g.TOP | g.LEFT);
}
}

class SegiempatCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
//menggambar kotak bewarna kuning
g.setColor(0,0,0);
g.drawRect(8,8,64,32);
g.setColor(255,255,0);
g.fillRect(8,8,64,32);
//menggambar berbagai macam jenis kotak
g.setColor(0,0,0);
g.drawRect(8,50,88,44);
g.drawRoundRect(108,50,88,44,18,18);
g.fillRect(8,120,88,44);
g.fillRoundRect(108,120,88,44,18,18);
}
}

class SudutCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(255,0,0);
g.drawArc(18,18,50,50,0,360);
g.setColor(0,255,0);
g.drawArc(40,40,100,120,0,180);
g.setColor(0,0,255);
g.fillArc(100,200,80,100,0,90);
}
}

class BungaCanvas extends Canvas {
protected void paint(Graphics g) {
// membersihkan layar dengan mengisi semua layar dengan warna hitam
g.setColor(0, 0, 0 );
g.fillRect(0, 0, getWidth(), getHeight());
//sudut ranting kanan atas
g.setColor(0, 255,0);
g.drawArc(80, 180, 50, 200,0, 180);
//sudur ranting kanan bawah
g.setColor(0, 255,0);
g.drawArc(80, 10, 50, 550,0, 180);
//kotak
g.setColor(0, 0,0);
g.fillRect(100,30,40,255);
//sudut bunga kuncup
g.setColor(0, 255,0); //green
g.fillArc(112, 30, 5, 23,0,360);
//sudut bunga kuncup //yellow
g.setColor(255, 255,0);
g.fillArc(112, 40, 5, 13,0,360);
//sudut ranting kiri atas
g.setColor(0, 255,0);
g.drawArc(-30, 50, 110, 450,0, 90);
//sudut ranting kiri tengah
g.setColor(0, 255,0);
g.drawArc(-50, 100, 130, 350,0, 90);
//sudut ranting kiri bawah
g.setColor(0, 255, 0);
g.drawArc(30, 200, 50, 150, 0, 90);
//sudut bulan
g.setColor(255, 255,255);
g.fillArc(150,20 , 60, 60,0,360);
//sudut awan kecil
g.setColor(200, 200,200);
g.fillArc(165,60, 20, 20,0,180);
//sudut awan besar
g.setColor(200, 200,200);
g.fillArc(180,45, 50, 50,0,180);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(130,10,4, 4,0,350);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(120,15,4, 4,0,350);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(125,30,5, 5,0,350);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(75,15,5, 5,0,350);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(40,25,4, 4,0,350);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(35,35,4, 4,0,350);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(220,30,5, 5,0,350);
//sudut bintang
g.setColor(255, 255,255);
g.fillArc(210,10,4, 4,0,350);
}

};

3 thoughts on “Program Menu J2ME

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