J2ME小特效之波浪字体

@Ta 2012-11-13 4401点击
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;

public class Midlet extends MIDlet {
Display display;

public Midlet() {
display = Display.getDisplay(this);
display.setCurrent(new DrawCanvas());
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}

protected void pauseApp() {

}

protected void startApp() throws MIDletStateChangeException {

}

}

/**
 * 进行低阶绘图的Canvas类
 * 
 * @author aflylove
 * @version 1.0
 */
class DrawCanvas extends Canvas implements Runnable {

/** 构造函数 */
private String str = new String("PRESS 5");
private int[] ak = { 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 0, 0, 0,
0, 0 };
boolean kaishi = true;
private int k = 6;

public DrawCanvas() {

new Thread(this).start();
}

protected void paint(Graphics g) {
g.setColor(0x00ffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x00000000);

for (int i = 0; i < str.length(); i++) {
g.drawString(str.substring(i, i + 1), 20 + i * 7, 10 - ak[k - i], 0);
g.drawString(str.substring(i, i + 1), 21 + i * 7, 11 - ak[k - i], 0);// 加重字体7是字体宽度
}

}

public void run() {
while (kaishi) {
try {
repaint(); // 再描绘
Thread.sleep(70); // 等待一定时间
k++;
if (k > (ak.length - 1))
k = 6;
} catch (InterruptedException e) {
}
}

}
}
回复列表(8|隐藏机器人聊天)
添加新回复
回复需要登录