Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Image Icon Using Canvas Example 
 

This example is used to create the Image on different location using Canvas class.

 

Image Icon Using Canvas Example

                         

This example is used to create the Image on different location using Canvas class. In this example to create the image we are using following code:

 

 

 

 

private Image image1, image2, image3;
image1 = Image.createImage("/cartoon.png");

image2 = Image.createImage("/girl-8-icon.png");

image3 = Image.createImage("/mancartoon.png");

And for draw the image we are using following code of lines:

g.drawImage(image1, 0, 0, Graphics.TOP | Graphics.LEFT);

g.drawImage(image2, getWidth() / 2, getHeight() / 2, Graphics.HCENTER | Graphics.VCENTER);

g.drawImage(image3, getWidth(), getHeight(), Graphics.BOTTOM | Graphics.RIGHT);

The application is as follows:

Source Code of ImageItemExample2.java

 

import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ImageItemExample2 extends MIDlet{
  private Display display;

  public void startApp(){
    display = Display.getDisplay(this);
    display.setCurrent(new ImageCanvas()); 
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){
    notifyDestroyed();
  }
}

class ImageCanvas extends Canvas{
  private Image image1, image2, image3;

  public ImageCanvas(){
    try{
      image1 = Image.createImage("/cartoon.png");
      image2 = Image.createImage("/girl-8-icon.png");
      image3 = Image.createImage("/mancartoon.png");
    }catch (IOException e){
      throw new RuntimeException("Unable to load Image: "+e);
    }
  }

  public void paint(Graphics g){
    g.setGrayScale(255);
    g.fillRect(00, getWidth(), getHeight());
    
    g.drawImage(image1, 00, Graphics.TOP | Graphics.LEFT);
    g.drawImage(image2, getWidth() / 2, getHeight() / 2, Graphics.HCENTER
     | Graphics.VCENTER);

    g.drawImage(image3, getWidth(), getHeight(), Graphics.BOTTOM
     | Graphics.RIGHT);

  }
}

Download Source Code

                         

» View all related tutorials
Related Tags: c j2me diff types type if example to rectangle draw exam raw angle e il pe in different m nt

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.