Home J2me Draw Clip Area Using Canvas
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Draw Clip Area Using Canvas

Advertisement
This Example is going to draw a clip with SOLID line. In this picture only solid line show the clipping area.

Draw Clip Area Using Canvas

     

This Example is going to draw a clip with SOLID line. In this picture only solid line show the clipping area. To draw a solid line, we have used SOLID keyword as given below:

setStrokeStyle(Graphics.SOLID)

and to draw the dotted line we are using DOTTED keyword, as given below:

setStrokeStyle(Graphics.DOTTED)

Methods, that are used in our example code..

  • setColor()
  • fillRect()
  • getWidth()
  • getHeight()
  • g.drawLine()
  • g.setClip()

 

Source Code of ClipExample.java

 

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ClipExample extends MIDlet{
  private Display display;
  
  public void startApp(){
  display = Display.getDisplay(this);
  display.setCurrent (new ClipCanvas())
  }

  public void pauseApp(){}

  public void destroyApp (boolean unconditional){}

  public void commandAction(){}
}

class ClipCanvas extends Canvas{
  public void paint(Graphics g){
  g.setColor(25500);
  g.fillRect(00, getWidth(), getHeight());

  int map = Math.min(getWidth(), getHeight());  
  g.setColor(00255);

  g.setStrokeStyle(Graphics.DOTTED);
  g.drawLine(00, map, map);

  g.setClip(map/4, map/4, map/2, map/2);

  g.setStrokeStyle(Graphics.SOLID);
  g.drawLine(00, map, map);
  }
}

 

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 1, 2008

Related Tutorials

Ask Questions?    Discuss: Draw Clip Area Using Canvas  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com