类似卫星扫描效果

王朝other·作者佚名  2008-05-31
宽屏版  字体: |||超大  

/*

Wireless java 2nd edition

Jonathan Knudsen

Publisher: APRess

ISBN: 1590590775

*/

import javax.microedition.lcdui.*;

import javax.microedition.lcdui.game.*;

import javax.microedition.midlet.*;

public class SweepGame extends MIDlet {

public void startApp() {

final SweepGameCanvas sweeper = new SweepGameCanvas();

sweeper.start();

sweeper.addCommand(new Command("Exit", Command.EXIT, 0));

sweeper.setCommandListener(new CommandListener() {

public void commandAction(Command c, Displayable s) {

sweeper.stop();

notifyDestroyed();

}

});

Display.getDisplay(this).setCurrent(sweeper);

}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

}

class SweepGameCanvas extends GameCanvas implements Runnable {

private boolean mTrUCking;

private int mTheta;

private int mBorder;

private int mDelay;

public SweepGameCanvas() {

super(true);

mTheta = 0;

mBorder = 10;

mDelay = 50;

}

public void start() {

mTrucking = true;

Thread t = new Thread(this);

t.start();

}

public void stop() {

mTrucking = false;

}

public void render(Graphics g) {

int width = getWidth();

int height = getHeight();

// Clear the Canvas.

g.setGrayScale(255);

g.fillRect(0, 0, width - 1, height - 1);

int x = mBorder;

int y = mBorder;

int w = width - mBorder * 2;

int h = height - mBorder * 2;

for (int i = 0; i < 8; i++) {

g.setGrayScale((8 - i) * 32 - 16);

g.fillArc(x, y, w, h, mTheta + i * 10, 10);

g.fillArc(x, y, w, h, (mTheta + 180) % 360 + i * 10, 10);

}

}

public void run() {

Graphics g = getGraphics();

while (mTrucking) {

mTheta = (mTheta + 1) % 360;

render(g);

flushGraphics();

try { Thread.sleep(mDelay); }

catch (InterruptedException ie) {}

}

}

}类似卫星扫描效果

(出处:http://www.knowsky.com)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有