Results 1 to 6 of 6
Thread: setFont GObject help
- 10-16-2010, 05:43 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 10
- Rep Power
- 0
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);
}
}
- 10-16-2010, 05:54 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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.
- 10-16-2010, 06:03 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 10
- Rep Power
- 0
The method setFont(Font) in the type GLabrl is not applicable for the arguments(String)
It also puts a red line under setFont
- 10-16-2010, 08:08 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
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"));
- 10-17-2010, 11:19 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 10
- Rep Power
- 0
Thank you for your help! I really very much appreciate it.
- 10-18-2010, 12:18 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Similar Threads
-
Can't use SetFont on Eclipse
By ccie007 in forum New To JavaReplies: 16Last Post: 05-30-2010, 04:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks