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.


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

Results 1 to 2 of 2

Thread: My bullseye won't show

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Thanked 0 Times in 0 Posts

    Default My bullseye won't show

    I'm working on a java assignment that requires me to draw a bullseye using Java.
    I think the code is straight, but it would draw anything--it just gives me a blank screen.

    Any help is appreciated

    Drawing the bullseye
    //Jeremiah A. Walker
    import java.awt.*;
    import javax.swing.*;
    public class BullsEye extends JPanel
    	public static void bullsEye(Graphics g, int x, int y, int diam, int count)
    		int r = diam; //fill oval uses width and height, I will use diam here
    		int xloc = x;
    		int yloc = y;
    		int offset = 0;
    		boolean change = true;
    		for(int j = 0; j < count; j++)
    			//must cast int divisor to float
    			//then cast the final result back to int
    			//also multiplying by r so its a percentage of diam
    			offset = (int)(r*(j*(1/(float)(count))));
    				change = false;
    			} else {
    				change = true;
    			}//end if/else
                    g.fillOval(xloc + offset/2, yloc + offset/2, r - offset, r - offset);
    		}//end for
    	}//end method bullsEye
    }//end class BullEye

    //Jeremiah A. Walker
    //Tester Program for SmileyFace.java
    //See SmileyFace.java for notes
    import javax.swing.*;
    public class BullsEyeTest
    	public static void main( String[] args )
    		BullsEye panel = new BullsEye();
    		JFrame application = new JFrame();
    		application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    		application.add( panel );
    		application.setSize( 230, 250 );
    		application.setVisible( true );
    	}//end main
    }//end class SmileyFaceTest

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 832 Times in 772 Posts
    Blog Entries

    Default Re: My bullseye won't show

    When do you expect your drawing code to be called? Add some println's in there to see its being called. I also recommend reading the following:
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

Similar Threads

  1. Show files name in JFrame
    By altisw5 in forum AWT / Java Swing
    Replies: 15
    Last Post: November 30th, 2011, 08:30 AM
  2. Hide/Show Form?
    By chickenhawk in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 1st, 2011, 06:26 AM
  3. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM
  4. Applet doesnt show
    By chonch in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 24th, 2011, 03:22 PM
  5. [SOLVED] Filling in alternating colors of a "BullsEye"
    By forte in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 22nd, 2010, 06:05 PM