Java - Applet - setFont

setFont() is a method in Java's Graphics class that allows you to set the font used for rendering text. It takes a Font object as an argument and sets it as the current font. The Font class is used to represent fonts in Java.

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

public class FontExample extends Applet {
   public void paint(Graphics g) {
      Font font = new Font("Serif", Font.BOLD, 20);
      g.setFont(font);
      g.drawString("Hello, World!", 50, 50);
   }
}

In this example, we create a Font object with the font family "Serif", a bold style, and a size of 20. We then set this font as the current font using the setFont() method. Finally, we use the drawString() method to render the string "Hello, World!" using the current font at position (50, 50).