Progyadeep Moulik Progyadeep Moulik - 6 months ago 3x
Java Question

Why does the Applet not produce output in the font I set?

I made an applet wherein I assigned the font properties to a Font class object f in the Applet class. In the paint() method I used the setFont() method to set the font properties of the current Graphics object to that of 'f'. But the drawString() method seems to display in the default font (maybe Arial) and not the font I set (though the font size, font style and colour was what I set). This is supposed to work according to the book I followed but isn't. Please find me the flaws in my code. Thanks.

/*Applet to use set Font*/

import java.applet.*;
import java.awt.*;

public class UsingFont extends Applet {

Font f=new Font("Algerian",Font.BOLD,30);

public void init() {}

public void paint(Graphics g) {
g.drawString("ALGERIAN FONT",20,15);


Maybe Algerian doesnt exist in your system so it substitutes the closest or default

try to see which fonts are available in your system:

GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] gf=ge.getAllFonts();
String[] gfn=ge.getAvailableFontFamilyNames();