graycanvas.java.svn-base

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

SVN-BASE
74
字号
package opusmicro.demos.gray;

import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class GrayCanvas extends Canvas implements CommandListener{
	SoftButton softButton;
	Font font = Font.getDefaultFont();
	Command leftCommand = new Command("Click",Command.OK,1);
	int w ,h;
	Image img;
	int index;
	public GrayCanvas() {
		softButton = new SoftButton();
		setFullScreenMode(true);
		w = getWidth();
		h = getHeight();
		initImage();
		softButton.init(this, font, leftCommand, null);
		softButton.setCommandListener(this);
	}
	Image initImage(){
		try {
			img = Image.createImage("/welcome.png");
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		return img;
	}
	public void keyPressed(int keyCode){
		softButton.keyPressed(keyCode);
	}
	protected void paint(Graphics g) {
		g.setColor(-1);
		g.fillRect(0, 0, w, h);
		paintObject(g);
		softButton.paint(g);
		if(index==1){
			g.setColor(0xABABAB);
			fillRect(g, 0, 0, w, h, 0xABABAB);
		}
	}
	private void paintObject(Graphics g){
		g.setColor(0xFF4500);
		g.fillRect(w/3, h/5, 80, 80);
		g.drawImage(img, w/4, h/2, 0);
		
	}
	public void fillRect(Graphics g, int x, int y,int w, int h,int ARGBColor) {
		int argb[] = new int[w * h];
		int a = 100;
		 for(int i=0;i<argb.length;i++){
			 argb[i] = (a<<24) | (argb[i]&0x00FFFFFF);
		 }
		 g.drawRGB(argb, 0, w, x, y,w, h, true);
	}
	public void commandAction(Command c, Displayable d) {
		if(c == leftCommand){
			index = (index+1)%2;
			System.out.println("click left command"+ index);
			repaint();
		}
	}

}

⌨️ 快捷键说明

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