程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> 會動的波浪字體

會動的波浪字體

編輯:J2ME


import Javax.microedition.lcdui.*;
import Javax.microedition.midlet.*;
public class DrawCanvas extends MIDlet implements CommandListener {
private Command exitCommand;
private HCanvas sg;
public DrawCanvas() {
exitCommand = new Command("Exit", Command.EXIT, 1);
sg = new HCanvas();
sg.addCommand(exitCommand);
sg.setCommandListener(this);
Display.getDisplay(this).setCurrent(sg);

}
protected void startApp(){
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0){
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class HCanvas 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 HCanvas (){
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){}
}
}
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved