网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > J2EE/J2ME
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.使用Timer和TimerTask实现欢迎界.
.J2EE中的异常管理及错误跟踪.
.WebLogicServer9.0应用的配置管理.
.漫谈EJB.
.JSP环境基于Session的在线用户统.
.J2ME中处理日期相关问题.
.游戏过场动画效果.
.JBoss 文档(三) JBoss和JMS.
.J2EE综合:选择JDO还是CMP?.
.MIDP终端模拟之二:高级终端模拟.
.在MySQL中添加表.
.精通Hibernate映射继承关系之五.
.熟练使用J2ME可选包MMAPI.
.Servlet2.3过滤器编程.
.入门:对J2EE初学者的学习流程介.
.整合.NET与J2EE两大平台化解争端.
.创建Mascot Capsule v3烟雾效果.
.Spring 系列:Spring JMS 消息处.
.在Spring中配置非Singleton.
.M3GConverter使用手册.

使用Timer制作动画效果

发表日期:2007-12-23


import Javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

public class TimerDemo extends MIDlet {

  Display    display;
  StarField  field = new StarField();
  FieldMover mover = new FieldMover();
  Timer      timer = new Timer();

  public TimerDemo() {
    display = Display.getDisplay( this );
  }

  protected void destroyApp( boolean unconditional ) { }

  protected void startApp() {
    display.setCurrent( field );
    timer.schedule( mover, 100, 100 );
  }

  protected void pauseApp() { }

  public void exit(){
    timer.cancel(); // stop scrolling
    destroyApp( true );
    notifyDestroyed();
  }

class FieldMover extends TimerTask {
  public void run(){
    field.scroll();
  }
}

class StarField extends Canvas {
  int        height;
  int        width;
  int[]      stars;
  Random     generator = new Random();
  boolean    painting = false;

  public StarField(){
    height      = getHeight();
    width       = getWidth();
    stars       = new int[ height ];

    forint i = 0; i < height; ++i ){
      stars[i] = -1;
    }
  }

  public void scroll() {
    if( painting ) return;

    forint i = height-1; i > 0; --i ){

      stars[i] = stars[i-1];
    }

    stars[0] = ( generator.nextInt() % ( 3 * width ) ) / 2;
    if( stars[0] >= width ){
      stars[0] = -1;
    }

    repaint();
  }

  protected void paint( Graphics g ){
    painting = true;

    g.setColor( 0, 0, 0 );
    g.fillRect( 0, 0, width, height );

    g.setColor( 255, 255, 255 );

    forint y = 0; y < height; ++y ){
      int x = stars[y];
      if( x == -1 ) continue;

      g.drawLine( x, y, x, y );
    }

    painting = false;
  }

  protected void keyPressed( int keyCode ){
    exit();
  }
}
}

使用Timer制作动画效果 

(出处:)


上一篇:JSP标准标签库(二) 人气:1726
下一篇:从自定义字节数组创建图片 人气:1116
浏览全部J2EE/J2ME的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐