DrawGRBCanvas.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:
J2ME
开发平台:
Java
- package DrawGRB;
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.*;
- import java.io.*;
- public class DrawGRBCanvas extends Canvas
- {
- private int[] pixelArray;
- public DrawGRBCanvas()
- {
- }
- public void paint(Graphics g)
- {
- g.setColor(0xFFFF00);
- g.fillRect(0, 0, this.getWidth(), this.getHeight());
- int x = 0, y = 0; // Where on the display to draw the image
- int width = 35, height = 35; // Size of the image
- // Define the array for image
- if(pixelArray == null)
- pixelArray = new int[width * height];
- // Create a fully opaque image, specifying only a value for red
- for(int i = 0; i < pixelArray.length; i++)
- pixelArray[i] = 0xffff0000;
- g.drawRGB(pixelArray, 0, width, x, y, width, height, false);
- g.drawRect(x, y, width, height); // Box the rectangle
- // Create a “half” opaque image, specifying only a value for red
- x = 35;
- y = 35;
- for(int i = 0; i < pixelArray.length; i++)
- pixelArray[i] = 0x7fff0000;
- g.drawRGB(pixelArray, 0, width, x, y, width, height, true);
- g.drawRect(x, y, width, height); // Box the rectangle
- x = 70;
- y = 70;
- // Create a fully transparent image, specifying only a value for red
- for(int i = 0; i < pixelArray.length; i++)
- pixelArray[i] = 0x00ff0000;
- g.drawRGB(pixelArray, 0, width, x, y, width, height, true);
- g.drawRect(x, y, width, height); // Box the rectangle
- }
- }