Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Confused by Garphics api

    Here is the code im trying to run for my OOP class.



    import java.awt.Graphics2D;
    import java.awt.Graphics;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import javax.swing.JComponent;

    // A component that draws a face

    public class FaceComponent extends JComponent
    {
    public void paintComponent(Graphics g)
    {
    //Recover Graphics2D
    Graphics2D g2 = (Graphics2D) g;


    //Draw Head
    Ellipse2D.Double head = new Ellipse2D.Double(5, 10, 150, 150);
    g2.draw(head);

    //Draw eyes
    Ellipse2D.Double eye = new Ellipse2D.Double(40, 50, 15, 15);
    g2.draw(eye);
    eye.translate(95, 0);//<--------THIS IS WHERE I GET THE ERROR 25
    g2.draw(eye);

    //Draw mouth
    Line2D.Double mouth = new Line2D.Double(30, 110, 120, 110);
    g2.draw(mouth);
    }
    }

    The error i get is: error 25 cannot find symbol. On the line that has eye.tanslate()
    but i check the api libary and the java.awt.Graphics has the translate method. Help!

    ps If I comment out that line and the one below everything works and I do have another .java file with a main class.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,423
    Rep Power
    5

    Default Re: Confused by Garphics api

    Graphics has it. But Ellipse2D.Double doesn't.


    Also, please place you code between [CODE][/CODE] tags to properly format you code. And you should also check out the FAQ and Guide for new members.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Confused by Garphics api

    Thanks for the response and I will take the time to read the FAQ and the Guide. Honestly I posted here not expecting a response as I have asked questions before on other forums and got nothing.

    Back to the question should I just make another new Ellipse2d.Double at the (x, y) i want or is there another way to do it that i am unaware of

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,423
    Rep Power
    5

    Default Re: Confused by Garphics api

    You are invoking translate from an instance of Ellipse2D.Double.

    Java Code:
    eye.translate(x,y); // wrong;
    
    g.translate(x,y); // correct!!
    g2.translate(x,y); // also correct!!
    //


    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

Similar Threads

  1. I'm so confused
    By minabarnes in forum New To Java
    Replies: 6
    Last Post: 01-14-2013, 04:16 AM
  2. Please Help! I'm Confused.
    By teekei in forum New To Java
    Replies: 1
    Last Post: 10-25-2011, 05:26 AM
  3. Help Please - I'm confused
    By NextToNothing in forum Threads and Synchronization
    Replies: 4
    Last Post: 07-04-2011, 11:37 PM
  4. Help i am so confused..:(
    By angeltiner in forum AWT / Swing
    Replies: 6
    Last Post: 04-11-2010, 01:43 AM
  5. I am confused
    By prof.deedee in forum New To Java
    Replies: 6
    Last Post: 10-30-2009, 11:32 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
  •