Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Filling in alternating colors of a "BullsEye"

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Filling in alternating colors of a "BullsEye"

    I'm back again with another question

    My code works...sort of. After I tried to fill in my bullseye with alternating blue and pink colors
    I get:
    -bullseye is pink
    -next circle is pink
    -next circle is pink
    -next circle is pink
    -last circle is blue

    I want:
    -bullseye to be blue
    -next circle to be pink
    -next circle to be blue
    -next circle to be pink
    -next circle to be blue

    I've tried deleting some "fillOval" but I can't seem to get what I need.

    package mis.hw2;
     
    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JFrame;
     
    @SuppressWarnings("serial")
    public class P2_BullsEye extends JFrame
    {
        //Declare Variables
        int centerX, centerY, outermostRadius, ringWidth;
     
        // Constructor
    public P2_BullsEye ()
        {
            super ("BullsEye");
            //Assign Variables
        }
     
    public void paint (Graphics g)
    {
            //Call the paint method of the JFrame
            super.paint (g);
     
        centerX = 150;
        centerY = 150;
        outermostRadius = 100;
        ringWidth = 22;
     
        //Make color blue
        g.setColor(Color.blue);
        //Draw blue Oval
        g.drawOval(125, 140, 20, 20);	
        g.drawOval(90, 110, 90, 80);	
        g.drawOval(50, 80, 170, 140);	
     
        //Fill blue Oval you just drew
        g.fillOval(125,140, 20, 20);
        g.fillOval(90, 110, 90, 80);
        g.fillOval(50, 80, 170, 140);
     
        //Make color pink
        g.setColor(Color.pink);
     
        //Draw pink Oval
     
        g.drawOval(70, 95, 130, 110);
     
        //Fill pink Oval you just drew
        g.fillOval(110, 125, 50, 50);
        g.fillOval(70, 95, 130, 110);
     
    }    
        public static void main(String args []) {
        // Create app object
        P04_BullsEye app = new P04_BullsEye();
        app.setSize(300, 300);
        app.setVisible(true);
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
     
        }
     
    }

    Am I missing a piece of code that makes my circle lines thicker or something?

    As always, thanks for any help!
    Sorry, I'm new


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Filling in alternating colors of a "BullsEye"

    The code you posted is confused - the bullseye class is called P2_Bullseye, but the main method is instantiating class P04_Bullseye. So what you've posted won't compile, and P2_Bullseye probably has nothing to do with your problem - and in any case has a bunch of redundant drawOval and fillOval calls. It only draws a pink oval inside a blue oval because that's all the code there is...
    Last edited by dlorde; May 22nd, 2010 at 02:08 PM.

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Filling in alternating colors of a "BullsEye"

    Quote Originally Posted by dlorde View Post
    The code you posted is confused - the bullseye class is called P2_Bullseye, but the main method is instantiating class P04_Bullseye. So what you've posted won't compile, and P2_Bullseye probably has nothing to do with your problem - and in any case has a bunch of redundant drawOval and fillOval calls. It only draws a pink oval inside a blue oval because that's all the code there is...
    Good eye! But your right, the P2 and P04 mix up is an error of me copying and pasting to here. My mistake, they should all be P2. I get no errors when compiling. I just don't get the correct output

    Could you explain the part of your comment that I bolded?

    I need to drawOval 5 times to draw 5 circles....dont I? Before I tried to fill the circles in with color, everything worked. I was able to draw 3 blue circles and 2 pink ones that mirrored a "bullsEye" ...just without any fill color.

    You also said that "It only draws a pink oval inside a blue oval because that's all the code there is." - I don't get this either... if I need to draw 5 circles, then wouldn't I need to incorporate 5 drawOvals and 5 fillOvals to draw and color in the 5 circles?
    Sorry, I'm new

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Filling in alternating colors of a "BullsEye"

    Figured it out. I had the order in which I was drawing the circles reversed.
    Sorry, I'm new

Similar Threads

  1. Replies: 1
    Last Post: March 31st, 2010, 09:42 PM
  2. Replies: 1
    Last Post: March 15th, 2010, 10:03 PM
  3. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  4. Replies: 1
    Last Post: October 25th, 2009, 11:54 AM
  5. Replies: 4
    Last Post: August 13th, 2009, 05:54 AM