Home J2me Draw Clip Area Using Canvas



Draw Clip Area Using Canvas
Posted on: November 1, 2008 at 12:00 AM
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

Related Tags for Draw Clip Area Using Canvas:
cipclilinethisidpingshowexamplepicturewithsolidtodrawexamrawpicshclippingeitarealiinmclpihowppxaxampssoclippinisippmplgoeaarssthshopleplppionlyonolonl


More Tutorials from this section

Ask Questions?    Discuss: Draw Clip Area Using Canvas  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.