component.java.svn-base

来自「example2 众多JAVA实例源码...学习java基础的好帮手」· SVN-BASE 代码 · 共 106 行

SVN-BASE
106
字号
package opusmicro.demos.animate2;

import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Graphics;

public class Component {

	private int width;
	private int height;
	private int x;
	private int y;
	public boolean isRunning = false;
	TweenAnimateCanvas tac;
	Thread thread;
	int moveY = 1;
	Timer timer;
	public Component(int x, int y, int width, int height,TweenAnimateCanvas tac) {
		this.setX(x);
		this.setY(y);
		this.setWidth(width);
		this.setHeight(height);
		this.tac = tac;
		timer = new Timer();
	}
	void spash() throws InterruptedException {
		for(int i=0;i<1;i++){
			tac.repaint(x,y,width,height);
			y--;
			Thread.sleep(100);
		}
		
		for(int i=0;i<3;i++){
			tac.repaint(x,y,width,height);
			y++;
			Thread.sleep(100);
		}
		for(int i=0;i<1;i++){
			tac.repaint(x,y,width,height);
			y--;
			Thread.sleep(100);
		}
	}
	
	public void paint(Graphics g, boolean isRunning){
		this.isRunning = isRunning;
		if(isRunning){
			g.setColor(0xaab);
			move();
		}else{
			g.setColor(0xeeab);
			stop();
		} 
		g.fillRect(x, y, width, height);
	}
	void stop(){
		timer.cancel();
		timer = new Timer();
	}
	void move(){
		try {
			timer.schedule(new TimerTask() {
				public void run() {
					try {
						spash();
					}
					catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}, 100,10);
			
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?