Tampilan :
Kode Pemograman
package Lab;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CaturMidlet extends MIDlet {
private Display display;
papancatur pantur;
public void startApp() {
if(display==null){
pantur = new papancatur(this);
display = Display.getDisplay(this);
}
display.setCurrent(pantur);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
protected void Quit(){
destroyApp(true);
notifyDestroyed();
}
class papancatur extends Canvas implements CommandListener{
private Command exitCommand = new Command("Exit", Command.EXIT, 0);
private CaturMidlet persegi;
public papancatur(CaturMidlet persegi){
this.persegi = persegi;
addCommand(exitCommand);
setCommandListener(this);
}
protected void paint(Graphics g) {
int width = getWidth();
int height = getHeight()-61;
g.setGrayScale(255);
g.fillRect(0, 0, width-1, height-1);
g.setColor(0, 0, 0); //pengaturan canvas warna hitam
//untuk potongan diagonal kanan
for (int baris = 0; baris < width; baris+=30) {
for (int kolom = 330; kolom>= 30; kolom-=60) {
g.fillRect(baris+kolom, baris, 30, 30);
}
}
//untuk potongan diagonal kiri
for (int baris = 0; baris < width; baris+=30) {
for (int kolom = 30; kolom <= 330; kolom+=60) {
g.fillRect(baris, baris+kolom, 30, 30);
}
}
}
public void commandAction(Command c, Displayable d) {
if(c==exitCommand){
persegi.Quit();
}
}
}
}
Kode Pemograman
package Lab;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CaturMidlet extends MIDlet {
private Display display;
papancatur pantur;
public void startApp() {
if(display==null){
pantur = new papancatur(this);
display = Display.getDisplay(this);
}
display.setCurrent(pantur);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
protected void Quit(){
destroyApp(true);
notifyDestroyed();
}
class papancatur extends Canvas implements CommandListener{
private Command exitCommand = new Command("Exit", Command.EXIT, 0);
private CaturMidlet persegi;
public papancatur(CaturMidlet persegi){
this.persegi = persegi;
addCommand(exitCommand);
setCommandListener(this);
}
protected void paint(Graphics g) {
int width = getWidth();
int height = getHeight()-61;
g.setGrayScale(255);
g.fillRect(0, 0, width-1, height-1);
g.setColor(0, 0, 0); //pengaturan canvas warna hitam
//untuk potongan diagonal kanan
for (int baris = 0; baris < width; baris+=30) {
for (int kolom = 330; kolom>= 30; kolom-=60) {
g.fillRect(baris+kolom, baris, 30, 30);
}
}
//untuk potongan diagonal kiri
for (int baris = 0; baris < width; baris+=30) {
for (int kolom = 30; kolom <= 330; kolom+=60) {
g.fillRect(baris, baris+kolom, 30, 30);
}
}
}
public void commandAction(Command c, Displayable d) {
if(c==exitCommand){
persegi.Quit();
}
}
}
}
0 komentar:
Posting Komentar