Java Reference
In-Depth Information
//**********************************************************
//**********************************************************
// Project: Java for Engineers
// Program: RGraphics
// Reference: Chapter 27
// Topics:
// 1. Creating the image object
// 2. Displaying a raster image
//**********************************************************
//**********************************************************
// Requires: ActiveFrame class in current directory
// Image file stars.gif in current directory
//**********************************************************
//**********************************************************
import java.awt.*;
//*********************************************
//*********************************************
// driving class
//*********************************************
//*********************************************
public class RasterGraphics extends ActiveFrame
{
// Class data
Image hstImage =
Toolkit.getDefaultToolkit().getImage(“HST_1.JPG”);
//*********************************
// redefinition of paint()
//*********************************
public void paint(Graphics g)
{
// Adjust the frame origin to the client area
g.translate(getInsets().left, getInsets().top);
// Display an image in .jpg format
g.drawImage(hstImage, 20, 20, 440, 400, this);
}
//****************************
// main
//****************************
public static void main(String[] args)
{
// Create an object of the class RasterGraphics
RasterGraphics aframe = new RasterGraphics();
// Use methods in superclasses to modify object's defaults
aframe.setSize(488, 470);
// Set frame size
Search WWH ::




Custom Search