开发学院软件开发Java 扫描屏幕和颜色渐变的效果 阅读

扫描屏幕和颜色渐变的效果

 2007-12-23 12:36:00 来源:WEB开发网   
核心提示:本例提供一个扫描屏幕的效果展示,其中扫描区域实现了基本的颜色渐变效果,扫描屏幕和颜色渐变的效果,除此之外,程序还包括了GameCanvas和线程的基本适用方法

本例提供一个扫描屏幕的效果展示,其中扫描区域实现了基本的颜色渐变效果。除此之外,程序还包括了GameCanvas和线程的基本适用方法,以及Graphics的绘图操作。

扫描屏幕和颜色渐变的效果

/*
 * SweepGame.java
 *
 * Created on 2005年12月2日, 下午1:25
 */

package com.j2medev.sweep;

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("退出", 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.cncms.com)


Tags:扫描 屏幕 颜色

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接