font getToolkit list

A friend loaned me the ancient Teach Yourself Java in 21 days from Sams Publishing.

In "Day 9", there is this vague reference to getToolkit().

"The fonts you have available to you in your applets depend on which fonts are installed on the system where the applet is running. If you pick a font for your applet and that font isn't available on the current system, Java will substitute a default font (usually Courier). You can get an array of the names of the current fonts available in the system using this bit of code: String[] fontslist = this.getToolkit().getFontList();"

I searched the API and it is confusing where it is located. The book says it is in java.awt.Font, the API says its in java.awt.Window.. another place in API says it is in java.awt.Toolkit. So I dont know where the hell it is.

Whatever the case, I cant figure out how to get it to work. Here is my code:

import java.awt.*;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Toolkit;

import java.awt.Window;

public class FontList{

public static void main(String args[]){

String[] fontslist = getToolkit().getFontList();

for(int i = 0; i < fontslist.length; i++){

System.out.println(fontslist +"\n");

}

}

}

What am I doing wrong? Thanks in advance for any assistance.

Regards

[1394 byte] By [javaxrockera] at [2007-11-26 13:36:51]
# 1

What you are doing wrong is using an old book, and not using Google or the api docs to realize that you are using very much outdated info.

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/GraphicsEnvironment.html#getAvailableFontFamilyNames is what you want to use, and here is the code that uses it. It took me less time to find that, than it took me to type this reply

import java.awt.GraphicsEnvironment;

public class TestCondition {

public static void main(String args[]) {

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

String[] fontslist = ge.getAvailableFontFamilyNames();

for (int i = 0; i < fontslist.length; i++) {

System.out.println(fontslist[i] + "\n");

}

}

}

~Tim

Message was edited by:

SomeoneElse

SomeoneElsea at 2007-7-7 22:22:54 > top of Java-index,Java Essentials,New To Java...