You Are Here:

Community: Wiki

This page was last modified on 16 September 2009, at 18:08.

How to Draw a circle in Java ME

From Forum Nokia Wiki

Reviewer Approved   

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

Image: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 Forum Nokia Java ME Developer's Library

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia