Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 15th, 2007, 07:06 PM
landon landon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 1 landon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 28 sec
Reputation Power: 0
Newbie java hello world question

The setFont method in the line with winner.setFont("Helvetica-24"); is not working. In the line setFont is underlined in red and the error messege is "The method setFont(Font) in the type GLabel is not applicable for the arguments (String)". I thought I did this perfectly correct but the editor says that there's an error. The setColor method is working, so I don't know why the setFont method won't work. Can anyone help me fix this?

I'm using Eclipse, if that means anything.

/*
* File: HelloProgram.java
* -----------------------
* This program displays "hello, world" on the screen.
* It is inspired by the first program in Brian
* Kernighan and Dennis Ritchie's classic book,
* The C Programming Language.
*/

import acm.graphics.*;
import acm.program.*;
import java.awt.Color;

public class HelloProgram extends GraphicsProgram {

public void run() {
GLabel winner = new GLabel("hello, world", 0, 100);
winner.setFont("Helvetica-24");
winner.setColor(Color.ORANGE);
add(winner);
}

}

Reply With Quote
  #2  
Old April 30th, 2007, 04:57 PM
bluescales bluescales is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 bluescales User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 26 sec
Reputation Power: 0
You probably need to input a java.awt.Font object. Go to (URL address blocked: See forum rules) and search "font" for instructions about the constructor.

Reply With Quote
  #3  
Old May 3rd, 2007, 07:38 PM
daniel_g daniel_g is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 60 daniel_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 3 m 50 sec
Reputation Power: 3
The setFont(Font f) method takes the argument 'Font f' , that is, an object type Font.
Your code does not give a Font object to the method, instead, you give a type String object: "Helvetica-24".

So what you should do, is create a new object type font:

Code:
/*
 * Creates a new object type Font: myfont
 */

  Font myFont = new Font("Helvetica", Font.PLAIN,  24);

Then you can add that object to the setFont method:
Code:
winner.setFont(myFont);

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Newbie java hello world question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT