All Packages This Package Class Hierarchy Class Search Index
Class Draw
java.lang.Object
|
+----java.awt.Component
|
+----Draw
public class Draw
extends java.awt.Component
{
// Fields 21
private static final int RAYS;
private static int[] xPoints1;
private static int[] xPoints10;
private static int[] xPoints2;
private static int[] xPoints3;
private static int[] xPoints4;
private static int[] xPoints5;
private static int[] xPoints6;
private static int[] xPoints7;
private static int[] xPoints8;
private static int[] xPoints9;
private static int[] yPoints1;
private static int[] yPoints10;
private static int[] yPoints2;
private static int[] yPoints3;
private static int[] yPoints4;
private static int[] yPoints5;
private static int[] yPoints6;
private static int[] yPoints7;
private static int[] yPoints8;
private static int[] yPoints9;
// Constructors 1
public Draw();
// Methods 4
public static void main(String[]);
public Dimension getPreferredSize();
public Dimension getSize();
public void paint(Graphics);
}
A demonstration of Java's basic graphics drawing primitives.
|
|
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 second Java example and shows basic graphics drawing primitives:
- drawRect
- fillRect
- drawArc
- fillArc
- drawLine
- drawPolyline
|
|
It should look like:
- Author:
-
Andrew Marriott.
,
© Curtin University of Technology 1998
private static final int RAYS
An integer constant which indicates how many rays
there are on the star.
private static int[] xPoints1
private static int[] yPoints1
private static int[] xPoints2
private static int[] yPoints2
private static int[] xPoints3
private static int[] yPoints3
private static int[] xPoints4
private static int[] yPoints4
private static int[] xPoints5
private static int[] yPoints5
private static int[] xPoints6
private static int[] yPoints6
private static int[] xPoints7
private static int[] yPoints7
private static int[] xPoints8
private static int[] yPoints8
private static int[] xPoints9
private static int[] yPoints9
Integer array which is used to hold the
coordinates of the bignose image.
private static int[] xPoints10
private static int[] yPoints10
public Draw()
The constructor does nothing special. The
super() constructor will be called by default.
This will construct the component we extend from.
See Also:
Component
public Dimension getSize()
Returns the size of this component.
Just returns our size. Why can't I use setSize()
and let the Component methods handle this?
- Overrides:
- getSize in class Component
See Also:
Dimension
public Dimension getPreferredSize()
Returns the preferred size of this component.
Just calls getSize(). Why do we need to do this?
- Overrides:
- getPreferredSize in class Component
See Also:
getSize
public void paint(Graphics graphics)
Draws the various objects on the Screen.
The paint method will erase the drawing area to the background
colour, and then set the foreground drawing colour.
The various geometric objects are then drawn on the screen
in the foreground Colour using the Graphics of the component.
Parameter | Description |
graphics | The graphics of the drawable surface. |
- Overrides:
- paint in class Component
See Also:
getSize, getBackground, getForeground, Graphics, setColor, drawRect, fillRect, drawArc, fillArc, drawLine, drawPolyline, getDefaultToolkit, sync
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