Results 1 to 6 of 6
  1. #1
    dhughes023 is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Java.awt.* Specifically Graphics Class

    Hello,
    So I am teaching a class and trying to use a simple setColor() function, however the method is apparently undefined in the Graphics class. Does anyone know why? I have copied and pasted the code.

    Using Eclipse
    Using JRE 7

    import java.applet.*;
    import java.awt.*;
    import java.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.*;

    public class Graphics extends JApplet
    {
    public void paint (Graphics page)
    {
    final int MID = 130;
    final int TOP = 50;
    setBackground (Color.cyan);


    page.setFont(new Font("TimesRoman", Font.PLAIN, 14));
    page.setColor();

    page.setColor (Color.blue);
    page.fillRect (0, 175, 300, 50); // ground
    page.setColor (Color.yellow);
    page.fillOval (260, -40, 80, 80); // sun
    page.setColor (Color.white);
    page.fillOval (MID-20, TOP, 40, 40); // head
    page.fillOval (MID-35, TOP+35, 70, 50); // upper torso
    page.fillOval (MID-50, TOP+80, 100, 60); // lower torso
    page.setColor (Color.red);
    page.fillOval (MID-3, TOP+50, 6, 6); // button
    page.fillOval (MID-3, TOP+60, 6, 6); // button
    page.setColor (Color.black);
    page.fillOval (MID-10, TOP+10, 5, 5); // left eye
    page.fillOval (MID+5, TOP+10, 5, 5); // right eye
    page.drawArc (MID-10, TOP+20, 20, 10, 10, 160); // frown
    page.drawLine (MID-25, TOP+60, MID-50, TOP+40); // left arm
    page.drawLine (MID+25, TOP+60, MID+55, TOP+60); // right arm
    page.drawLine (MID-20, TOP+5, MID+20, TOP+5); // brim of hat
    page.fillRect (MID-15, TOP-20, 30, 25); // top of hat
    page.drawString ("John Lewis", 20, 20); // artist




    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Java.awt.* Specifically Graphics Class

    Hint: What function are you trying to use? How many arguments does it take? How many are you supplying?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    dhughes023 is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Re: Java.awt.* Specifically Graphics Class

    The exact error for the correct setColor()'s is this "The method setColor(Color) is undefined for the type Graphics" I thought it passed a Color type.

  4. #4
    dhughes023 is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Re: Java.awt.* Specifically Graphics Class

    I understand the first setColor() with no parameter is wrong, haha

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Java.awt.* Specifically Graphics Class

    Ah, I see another problem. You're naming your class Graphics, which is hiding java.awt.Graphics. That's one reason reusing existing class names is a big no-no.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    dhughes023 is offline Member
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default Re: Java.awt.* Specifically Graphics Class

    That was it! Thank you so much. It was driving me nuts. I can't believe I named a new class the same as an existing one. Lesson learned there! The Graphics class is still not popping up as a suggestion when I start with java.awt.... but it let me put the Graphics class there manually. Anyway, thanks again! I was going crazy! haha

Similar Threads

  1. Graphics abstract class
    By curious_programmer in forum New To Java
    Replies: 2
    Last Post: 06-05-2012, 12:23 PM
  2. The Graphics Class
    By Everyman in forum New To Java
    Replies: 5
    Last Post: 02-10-2012, 04:38 PM
  3. Replies: 2
    Last Post: 06-07-2011, 09:00 AM
  4. ending a graphics class
    By imorio in forum AWT / Swing
    Replies: 11
    Last Post: 08-16-2010, 05:41 PM
  5. Problem in g.drawArc() api of Graphics class
    By narasimman in forum AWT / Swing
    Replies: 0
    Last Post: 07-30-2008, 08:19 AM

Posting Permissions

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