Revision as of 06:25, 6 February 2012 by hamishwillee (Talk | contribs)

How to Draw a circle in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: senthil_k (19 Nov 2007)
Last edited: hamishwillee (06 Feb 2012)

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

JavaME HowToDrawACircle.png



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.fillRect(0, 0, getWidth(), getHeight());
graphics.drawArc(0, 0, getWidth(), getHeight(), 0, 360);

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


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

157 page views in the last 30 days.