TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
GAMELOFT新出的游戏MiamiNights中开始页面有个 波浪字体很漂亮, “PRESS 5” 7个字符依次向空中飞起再落下 晚上想了下写了出来.

- 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){}
- }
- }
- }
复制代码
源码下载:http://203.93.208.26/kj/cwb/dir7/DrawCanvas.zip |
|