Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 23:32, 13 December 2013 by lpvalente (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to Draw a circle in Java ME

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: senthil_k (19 Nov 2007)
Last edited: lpvalente (13 Dec 2013)

This article explains how to draw a circle by using Java ME low-level APIs.

JavaME HowToDrawACircle.png

Contents

Description

When working with low-level Graphics, it's possible to draw simple shapes just using the available Graphics methods:

  • drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
  • drawLine(int x1, int y1, int x2, int y2)
  • drawRect(int x, int y, int width, int height)
  • drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)


Source code

The following code shows the paint method of a Canvas class which helps to draw a circle in Java ME

protected void paint(Graphics graphics)
{
graphics.setColor(255,255,255);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.setColor(255,0,0);
graphics.drawArc(0, 0, getWidth(), getHeight(), 0, 360);
}

To draw a filled circle, just replace the drawArc() method with fillArc().

Download

You can download the source code presented in this article here: Media:DrawACircleMIDlet.zip

Related resources

Low-level APIs on Nokia Developer Java ME Developer's Library

This page was last modified on 13 December 2013, at 23:32.
116 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×