ClipCanvas.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:1k
源码类别:

J2ME

开发平台:

Java

  1. package Clip;
  2. import javax.microedition.lcdui.*;
  3. import javax.microedition.midlet.*;
  4. import java.io.*;
  5. public class ClipCanvas extends Canvas
  6. {
  7. public ClipCanvas()
  8.         {
  9.     
  10.         }
  11.         public void paint(Graphics g)
  12.         {
  13.         System.out.println("区域原点"+g.getClipX());
  14.         System.out.println("区域原点"+g.getClipY());
  15.         System.out.println("区域宽度:"+g.getClipWidth());
  16.         System.out.println("区域高度:"+g.getClipHeight());
  17.         System.out.println("画布宽度:"+getWidth());
  18.         System.out.println("画布高度:"+getHeight());
  19.         
  20.         /*g.setColor(0x000000);
  21.         int canvasWidth = getWidth();
  22.         int canvasHeight = getHeight();
  23.         g.fillRect(0,0,canvasWidth,canvasHeight);
  24.         g.setClip(canvasWidth/4,canvasHeight/4,canvasWidth/2,canvasHeight/2);
  25.         g.setColor(0xFFFFFF);
  26.         g.fillRect(0,0,canvasWidth,canvasHeight);*/
  27.         g.setColor(0x000000);
  28.         int canvasWidth = getWidth();
  29.         int canvasHeight = getHeight();
  30.         g.fillRect(0,0,canvasWidth,canvasHeight);
  31.         g.setClip(canvasWidth/4,canvasHeight/4,canvasWidth/2,canvasHeight/2);
  32.      //   g.setClip(0,0,0,0);
  33.         g.setColor(0xFFFFFF);
  34.         g.fillRect(0,0,canvasWidth,canvasHeight);
  35.         g.clipRect(0,0,canvasWidth/2,canvasHeight/2);
  36.         g.setColor(0xFF0000);
  37.         g.fillRect(0,0,canvasWidth,canvasHeight);
  38.    
  39.         }
  40.         
  41. }