Displaying Text:

  1. Displaying a text string:

    g2.drawString(Text, xLeft, yBase)

  2. Font is a style of letter type

    Example of fonts:

  3. A Font has 3 properties:

    1. Font face name
      • A logical face name
        • "Serif" (good for intensive reading)
        • "SansSerif" (good for display - like table caption)
        • "Monospaced" (each letter hass same width)
        • "Dialog"
        • "DialogInput"

      • or a type face name
        • "Times Roman" (a "Serif" font)
        • "Helvetica" (a "SansSerif" font)
        • "Courier" (a "Monospaced" font)
        • ...

    2. Font style
      • Plain
      • Bold
      • Italic
      • Bold+Italic

    3. Point size
      • Any integer value
      • 1 point = 1/72 inch
      • a "small" size font is about 8 points
      • a "medium" size font is about 12 points
      • a "large" size font is about 18 points
      • a "huge" size font is about 36 points

  4. To set the current font in Graphics2D object g2:

    g2.setFont(FontObject)

  5. Create your own font objects in Java:

    Font myFont = new Font("FontFace", Style, pointSize)

    • "FontFace"
      • "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput"
      • "Times Roman", "Helvetica", "Courier", etc

    • Style:
      • Font.PLAIN
      • Font.BOLD
      • Font.ITALIC
      • Font.BOLD + Font.ITALIC

    • pointSize: (positive) integer

    Documentation for java.awt.Font: click here