Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-27-2008, 04:02 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
Circles (Loops)
I have to write and applet in which I draw 4 concentric circles. I have to use this code looped 4 times. Not only do I have to loop it. I have to make each circle. Each circle's radius must be twice as large as the circle before it.

Code:
g.drawOval()
Thanks.
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-29-2008, 08:38 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
// <applet code="ConcentricApplet" width="400" height="400"></applet> import java.awt.*; import javax.swing.*; public class ConcentricApplet extends JApplet { public void init() { setLayout(new BorderLayout()); add(new ConcentricPanel()); } } class ConcentricPanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); int r = Math.min(w, h)/8; int cx = w/2; int cy = h/2; for(int i = 0; i < 4; i++) { int d = (i+1)*r; int x = cx - d/2; int y = cy - d/2; g2.drawOval(x, y, d, d); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about loops BHCluster New To Java 4 04-16-2008 07:40 PM
[SOLVED] Need help with Loops...please! Zebra New To Java 5 04-10-2008 03:44 PM
Loops (while do etc) manupr New To Java 1 01-15-2008 05:59 AM
Nested loops? gabriel New To Java 4 08-06-2007 06:51 PM
Help me: loops in java silvia New To Java 3 07-19-2007 08:47 PM


All times are GMT +3. The time now is 09:41 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org