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 5 of 5

Thread: Cannot Find Symbol

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Cannot Find Symbol

    /*
    Paulino Rosado
    09/24/2012
    Draw a bullseye
    */
    import javax.swing.JApplet;
    import java.awt.*;
    public class BullseyeApplet extends JApplet
    {
    	private void drawCircle(Graphics g, int centerX, int centerY, int diameter, Color color)
    	{
    		g.setColor(color);
    		g.fillCircle(centerX - diameter/2,centerY - diameter/2,diameter,diameter);
    	}
    	public void paint(Graphics g)
    	{
    		drawCircle(g, 100, 100, 175, Color.GREEN);
    		drawCircle(g, 100, 100, 150, Color.BLUE);
    		drawCircle(g, 100, 100, 125, Color.GREEN);
    		drawCircle(g, 100, 100, 100, Color.BLUE);
    		drawCircle(g, 100, 100, 75, Color.GREEN);
    		drawCircle(g, 100, 100, 50, Color.BLUE);
    	}
    }

    C:\Users\Chico\Documents\BullseyeApplet.java:13: error: cannot find symbol
    		g.fillCircle(centerX - diameter/2,centerY - diameter/2,diameter,diameter);
    		 ^
      symbol:   method fillCircle(int,int,int,int)
      location: variable g of type Graphics

    That's my code, for some reason it recognizes g.setColor(color);, but it won't recognize any other instance of g. I don't understand why!
    Last edited by ChicoTheMan94; September 25th, 2012 at 02:36 PM.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Cannot Find Symbol

    You have several uses of g outside the scope where g was declared.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Cannot Find Symbol

    Quote Originally Posted by jps View Post
    You have several uses of g outside the scope where g was declared.
    Ah yes, ignore that, I fixed that part, was more focused on why g.fillCircle was not being recognized. I'll edit the post code real quick!

  4. #4
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: Cannot Find Symbol

    Quote Originally Posted by ChicoTheMan94 View Post
    ...
    		g.fillCircle(centerX - diameter/2,centerY - diameter/2,diameter,diameter);
    ...

    C:\Users\Chico\Documents\BullseyeApplet.java:13: error: cannot find symbol
    		g.fillCircle(centerX - diameter/2,centerY - diameter/2,diameter,diameter);
    		 ^
      symbol:   method fillCircle(int,int,int,int)
      location: variable g of type Graphics
    If it says it can't find fillCircle(), maybe there is no such method for Graphics. Do you, perhaps, need to use fillOval()?


    Cheers!

    Z
    Last edited by Zaphod_b; September 25th, 2012 at 02:47 PM.

  5. The Following User Says Thank You to Zaphod_b For This Useful Post:

    ChicoTheMan94 (September 25th, 2012)

  6. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Cannot Find Symbol

    Quote Originally Posted by Zaphod_b View Post
    If it says it can't find fillCircle(), maybe there is no such method. Do you, perhaps, need to use fillOval()?

    Cheers!

    Z
    *Cough*
    Look, the real question here is not who meant to use what, the real question is, how fast can we ignore this and pretend I DIDN'T use circle.

    EDIT:
    Hey I did the frame version without error, yay I'm getting better at graphics! I'm terrible with it right now T_T
    /*
    Paulino Rosado
    09/24/2012
    Draw a bullseye
    */
    import javax.swing.JFrame;
    import java.awt.*;
    public class Bullseye extends JFrame
    {
    	public Bullseye()
    	{
    	}
    	private void drawCircle(Graphics g,int centerX,int centerY,int diameter,Color color)
    	{
    		g.setColor(color);
    		g.fillOval(centerX-diameter/2,centerY-diameter/2,diameter,diameter);
    	}
    	public void paint(Graphics g)
    	{
    		drawCircle(g, 100, 125, 175, Color.GREEN);
    		drawCircle(g, 100, 125, 150, Color.BLUE);
    		drawCircle(g, 100, 125, 125, Color.GREEN);
    		drawCircle(g, 100, 125, 100, Color.BLUE);
    		drawCircle(g, 100, 125, 75, Color.GREEN);
    		drawCircle(g, 100, 125, 50, Color.BLUE);
    	}
    	public static void main(String[]args)
    	{
    		Bullseye frame = new Bullseye();
    		frame.setSize(255,255);
    		frame.setTitle("Bullseye");
    		frame.setVisible(true);
    	}
    }
    Last edited by ChicoTheMan94; September 25th, 2012 at 02:50 PM.

Similar Threads

  1. cannot find symbol
    By lanpan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 1st, 2012, 08:13 AM
  2. Cannot find symbol
    By waarten in forum What's Wrong With My Code?
    Replies: 18
    Last Post: January 11th, 2012, 03:15 PM
  3. Cannot find symbol
    By BadgerWatch in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 6th, 2011, 11:25 PM
  4. Cannot find Symbol?
    By defmetalhead in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 5th, 2011, 08:48 AM
  5. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 10:02 PM