All Packages  This Package  Class Hierarchy  Class Search  Index

Class Fonts
java.lang.Object
   |
   +----java.awt.Component
           |
           +----Fonts

  Summary

public class  Fonts
     extends java.awt.Component
{
          // Fields 2
     private static final String alphabet0;
     private static final String alphabet1;

          // Constructors 1
     public Fonts();

          // Methods 4
     public static void main(String[]);

     public Dimension getPreferredSize();
     public Dimension getSize();
     public void paint(Graphics);
}

A demonstration of Java's basic Font primitives.

Create a new Class that extends the java.awt.Component class. This means that we will inherit various data and methods from this class. The component is the basic drawing class for graphics.

This is the third Java example and shows basic Font primitives:
  • getFont
  • setFont
  • drawString
  • getFontList
  • getName

It should look like:

Author:
© Andrew Marriott. , Curtin University of Technology 1998




  Fields

· alphabet0

Summary  |  Top

   private static final String alphabet0


· alphabet1

Summary  |  Top
   private static final String alphabet1

The strings of characters displayed on the screen.


  Constructors

· Fonts

Summary  |  Top

   public Fonts() 

Our constructor does nothing special. The super() constructor will be called by default. This will construct the component we extend from.

See Also: Component



  Methods

· getSize

Summary  |  Top
   public Dimension getSize() 

Returns the size of this component. Just returns our size.

Overrides:
getSize in class Component

See Also: Dimension



· getPreferredSize

Summary  |  Top
   public Dimension getPreferredSize() 

Returns the preferred size of this component. Just calls getSize().

Overrides:
getPreferredSize in class Component

See Also: getSize



· paint

Summary  |  Top
   public void paint(Graphics graphics) 

Draws the various objects on the Screen.

Our paint method will erase the drawing area to the background colour, and then set the foreground drawing colour.

The various fonts are then drawn on the screen, one after the other using the Graphics of the component.

Note that the height of the font is not used - see a later example. Hence some systems may see the fonts run off the screen!!

Parameter Description
graphics The graphics of the drawable surface.

Overrides:
paint in class Component

See Also: getSize, getBackground, getForeground, Graphics, setColor, fillRect, getFont, drawString, setFont, getName, getDefaultToolkit, getFontList, sync



· main

Summary  |  Top
   public static void main(String[] args) 

Test the new Component.

Create a Frame to hold the component, create the component and then set it's foreground and background colour.
Add the component to the Frame and then pack the Frame. Then make it all visible on the screen.

Parameter Description
args The arguments passed in from the invocation of this java class. First element is NOT name of program.

See Also: Frame, setBackground, setForeground, add, pack, setVisible



All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7