Java Reference
In-Depth Information
stretched and shrunk, and even animated, by applying translation, scal-
ing, and rotation transformation. For example, the vector-based arms of a
graphical clock can be made to move by applying a series of rotation
transformations. An object can be made to move diagonally across the
screen by consecutively applying a translation transformation. In either
case the graphics application would have to follow a cycle of drawing,
transforming, erasing, and redrawing each image.
The sample program named VGraphics, listed below, shows some of
the fundamental manipulations in Java vector graphics.
//**********************************************************
//**********************************************************
// Project: Java for Engineers
// Program: VGraphics
// Reference: Chapter 27
// Topics:
// 1. Translating the frame origin to the client area
// 2. Creating and using colors
// 3. Vector graphics
//**********************************************************
//**********************************************************
// Requires: ActiveFrame class in the current directory
//**********************************************************
//**********************************************************
import java.awt.*;
//*********************************************
//*********************************************
// driving class
//*********************************************
//*********************************************
public class VGraphics extends ActiveFrame
{
// Class data
int[] xCoords = {350, 500, 500, 350};
int[] yCoords = {50, 150, 50, 150};
//*********************************
// redefinition of paint()
//*********************************
public void paint(Graphics g)
{
// Adjust the frame origin to the client area
g.translate(getInsets().left, getInsets().top);
// Select a font
Font f = new Font(“Monospaced”, Font.BOLD, 16);
g.setFont(f);
Search WWH ::




Custom Search