Results 1 to 2 of 2

Thread: Circles (Loops)

  1. #1
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Louisville, Indiana/Kentucky
    Rep Power

    Default 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.

    Java Code:
    I am a Java n00b.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    Java 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) {
            Graphics2D g2 = (Graphics2D)g;
            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);

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts