Results 1 to 6 of 6
  1. #1
    Hollywood_99 is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default setFont GObject help

    I am really new to Java, and I have been following a tutorial and I have written the code exactly as it is on the screen and I am getting an error with SetFont, (it's underlined in red). I am using Eclipse and I believe I have the latest build of Java for Mac. For the life of me...I don't know why it's not working...

    Here is my code:


    import java.awt.Color;
    import java.awt.Font;

    import acm.program.*;
    import acm.graphics.*;



    /*
    * HelloProgram
    */


    public class HelloProgram2 extends GraphicsProgram {

    public void run() {
    GLabel label = new GLabel( "hello, world", 100, 75);
    label.setFont("Helvetica-24"); // <-- This line
    label.setColor(Color.RED);
    add(label);
    }


    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    What is the actual error?

    According to the GLbel API docs there is a setFont() method that takes a string argument.

    Make sure you don't have any other class with the name GLabel hanging around. Ie there should not be a file GLabel.java in the same directory.

  3. #3
    Hollywood_99 is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    The method setFont(Font) in the type GLabrl is not applicable for the arguments(String)

    It also puts a red line under setFont

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    That's weird unless you are using a different version of the acm library from the tutorial (and the docs I linked to). Try using the setFont() version that takes a Font argument:

    Java Code:
    label.setFont(Font.decode("Helvetica-24"));

  5. #5
    Hollywood_99 is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    Thank you for your help! I really very much appreciate it.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

Similar Threads

  1. Can't use SetFont on Eclipse
    By ccie007 in forum New To Java
    Replies: 16
    Last Post: 05-30-2010, 05:56 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
  •