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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Draw arc in J2ME 
 

The given example is going to draw an arc using canvas class of J2ME. You can also set a color for it, as we did in our example.

 

Draw arc in J2ME

                         

The given example is going to draw an arc using canvas class of J2ME. You can also set a color for it, as we did in our example.

Different methods that are used in this example...

g.setColor(00255);

g.fillRect(00, getWidth(), getHeight());

g.setColor(25500);

g.fillArc(15,1520020090, degree);

display.callSerially(this);

g.setColor(25500);

g.drawArc(15152002000360);

In this example, circle will start moving every time the MIDlet will be started and the repaint() method will be called .

The application will look like as follow..

 

 

Source Code of RunningCircle.java

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

public class RunningCircle extends MIDlet{
  
  public void startApp(){
    Display display = Display.getDisplay (this);
    display.setCurrent(new CircleCanvas(display, 10))
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){}
}

class CircleCanvas extends Canvas implements Runnable{
  int degree = 360;
  long startTime;
  int seconds;
  Display display;

  CircleCanvas(Display display, int seconds){
    this.display = display;
    this.seconds = seconds;
    startTime = System.currentTimeMillis();
  }

  public void paint(Graphics g){
    g.setColor(00255);
    g.fillRect(00, getWidth(), getHeight());

    g.setColor(25500);
    g.fillArc(15,1520020090, degree);
    display.callSerially(this);
    g.setColor(25500);
    g.drawArc(15152002000360);
  }

  public void run(){
    int i = 0;
    int milisecond = (int)((System.currentTimeMillis() - startTime)/seconds)
    degree = 360 (milisecond * 360)/7200;
    for(i = 0; i <= milisecond; i++){
      repaint();
    }
  }
}

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.