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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Co-ordinates MIDlet Example 
 

In this example the CoordinatesCanvas class extends the Canvas class to draw the image and fill color as given below in the figure.

 

Co-Ordinates MIDlet Example

                         

In this example the CoordinatesCanvas class extends the Canvas class  to draw the image and fill color as given below in the figure. The following methods is used to draw the image:

  • image = Image.createImage(100, 100);         
  • Graphics g = image.getGraphics();         
  • g.setColor(110,110,110);         
  • g.fillArc(10, 10, 50, 50, 120, 120);

In the paint(Graphics g) function the following methods is used to color the image:

  • g.setColor(255,255,0);         
  • g.fillRect(0, 0, getWidth(), getHeight());         
  • g.translate(45, 45);         
  • g.drawImage(image, 0, 0, Graphics.VCENTER | Graphics.HCENTER);

Simply the commandAction function is used to exit the current window and the application is as follows:

 

Source Code of Coordinates.java

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

public class Coordinates extends MIDlet{
  private Display  display;     
  private CoordinatesCanvas canvas;   
  
  public Coordinates (){
    display = Display.getDisplay(this);
    canvas  = new CoordinatesCanvas();
  }

  protected void startApp(){
    display.setCurrent( canvas );
  }

  protected void pauseApp(){ }

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

  class CoordinatesCanvas extends Canvas implements CommandListener{
    private Command exit;  
    private Image image;
    
    public CoordinatesCanvas(){
      exit = new Command("Exit", Command.EXIT, 1);
      addCommand(exit);
      setCommandListener(this);
      try{
        image = Image.createImage(100100);
        Graphics g = image.getGraphics();
        g.setColor(110,110,110);
        g.fillArc(10105050120120);      
      }catch (Exception error){
        Alert alert = new Alert("Failure""Creating Image", null, null);
        alert.setTimeout(Alert.FOREVER);
        display.setCurrent(alert);
      }    
    

    protected void paint(Graphics g){
      if (image != null){
        g.setColor(255,255,0);
        g.fillRect(00, getWidth(), getHeight());
        g.translate(4545);
        g.drawImage(image, 00, Graphics.VCENTER | Graphics.HCENTER);    
      }
    }

    public void commandAction(Command command, Displayable display){
      String label = command.getLabel();
      if (label.equals("Exit")){
        destroyApp(true);
      }
    }
  }
}

Download Source Code

                         

» View all related tutorials
Related Tags: c string image text io colors user color screen display click source cli message set create define show tex example

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.