-1

How do I import a font into a Java applet with AWT? I don't want a solution in Swing, so don't bother if that's your advice, thanks.

I know I would have to have the TTF file but then I don't know how to make my applet use the file for my text.

  • `java.awt.Font` is used by both AWT and Swing, so the process of loading the font is the same – MadProgrammer Sep 13 '14 at 08:38
  • So how do you import a custom made font file? – user3414510 Sep 13 '14 at 08:49
  • 1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. – Andrew Thompson Sep 13 '14 at 23:20

1 Answers1

0
  1. Load the font using Font#createFont(int, InputStream) . You can use it directly, but it's better if...
  2. Register the font with the system GraphicsEnvironment#registerFont

As mentioned:

Updated...

In order to be able to use a Font within a Applet context, you the Font file will need to be included within your applets Jar file.

You will then need to use something like...

InputStream is = getClass().getResourceAsStream("/path/to/font file");

Where the path is relative to your class files.

You would then use this to load the Font

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366