All Packages  This Package  Class Hierarchy  Class Search  Index

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

  Summary

public class  Colours
     extends java.awt.Component
{
          // Fields 6
     private static final int RAYS;
     private static final String alphabet0;
     private static final String alphabet1;
     private static final String alphabet2;
     private Bignose bignose;
     private Bignose colouredBignose;

          // Constructors 1
     public Colours();

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

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

A demonstration of Java's Colour capabilities.

Creates 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 fourth Java example and shows Colour capabilities:
  • setColor
  • Color.xxx

It also shows better Java programming style including Font heights, use of classes for encapsulation, etc.

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


· alphabet2

Summary  |  Top
   private static final String alphabet2

The constant strings of characters displayed on the screen.


· RAYS

Summary  |  Top
   private static final int RAYS

An integer constant which indicates how many rays there are on the star.


· bignose

Summary  |  Top
   private Bignose bignose

This object encapsulates the data and painting attributes for a big Nose. It also has a setColours method to set the drawing colours of the upper and lower parts of the Face.

See Also: Bignose, setColours


· colouredBignose

Summary  |  Top
   private Bignose colouredBignose

This object encapsulates the data and painting attributes for a big Nose. It also has a setColours method to set the drawing colours of the upper and lower parts of the Face.

See Also: Bignose, setColours


  Constructors

· Colours

Summary  |  Top

   public Colours() 

Our constructor creates two instances of a Bignose object. These will later be used to paint the bignoses.

super() constructor will be called by default. This will construct the component we extend from. Note The normal java class is Color not Colour.

See Also: Component, Bignose, setColours



  Methods

· getSize

Summary  |  Top
   public Dimension getSize() 

Returns the size of this component. Just returns our size. Still uses hardwired values.

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 coloured 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 objects are then drawn on the screen in different colours using the Graphics of the component.

The fonts are drawn using the correct font heights for spacing.

Parameter Description
graphics The graphics of the drawable surface.

Overrides:
paint in class Component

See Also: getSize, getBackground, getForeground, paint, Graphics, setColor, drawRect, fillRect, drawArc, fillArc, drawLine, drawPolyline, drawString, setFont, getFontMetrics, getHeight, getName, Bignose, paint, getDefaultToolkit, 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