Thread ker:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class ThreadBackgroudCanvas extends GameCanvas implements Runnable {
private boolean isPlay;
private long delay;
private int currentX, currentY;
private int width;
private int height;
private int x;
public ThreadBackgroudCanvas() {
super(true);
width = getWidth();
height = getHeight();
currentX = width / 2;
currentY = height / 2;
delay = 20;
}
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() {
isPlay = false;
}
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
x++;
if(x<-120) {
x=0;
}else {
x=x-5;
}
drawScreen(g);
try { Thread.sleep(delay); }
catch (InterruptedException ie) { }
}
}
private void drawScreen(Graphics g) {
try {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
Image image = Image.createImage("/gbr-bg.png");
g.drawImage(image, x, (getHeight()-image.getHeight())/2, Graphics.TOP | Graphics.LEFT);
}catch(Exception e){ }
flushGraphics();
}
}
selamat mencoba!
Sabtu, 21 Februari 2009
lab aktiviti 2
by lutvi
Langganan:
Posting Komentar (Atom)
0 comment:
Posting Komentar