Java Swing Tutorial - Java Font.toString()








Syntax

Font.toString() has the following syntax.

public String toString()

Example

In the following code shows how to use Font.toString() method.

/*from   w  ww .  j  av a2  s  .  co  m*/
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JFrame;

public class Main extends JFrame {

  public static void main(String[] a) {
    Main f = new Main();
    f.setSize(300, 300);
    f.setVisible(true);
  }

  public void paint(Graphics g) {
    Font f = g.getFont();
    
    System.out.println(f.toString());

     

    g.drawString("java2s.com", 4, 16);
  }
}