CH09-ObjectOrientedGraphics

CH09-ObjectOrientedGraphics - The Art and Science of An...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Art and Science of An Introduction to Computer Science ERIC S. ROBERTS Jav a Object-oriented Graphics C H A P T E R 9 Yea, from the table of my memory I’ll wipe away all trivial fond records. —William Shakespeare, Hamlet, c. 1600 9.1 The acm.graphics model 9.2 Structure of the acm.graphics package 9.3 Using the shape classes 9.4 Creating compound objects The acm.graphics Model • The acm.graphics package uses a collage model in which you create an image by adding various objects to a canvas. • A collage is similar to a child’s felt board that serves as a backdrop for colored shapes that stick to the felt surface. As an example, the following diagram illustrates the process of adding a red rectangle and a green oval to a felt board: • Note that newer objects can obscure those added earlier. This layering arrangement is called the stacking order . The Java Coordinate System • As you know from your experience with the acm.graphics package, all distances and coordinates in the graphics library are measured in pixels , which are the tiny dots that cover the surface of the screen. • Coordinates in the graphics model are specified relative to the origin in the upper left corner of the screen. • Coordinate values are specified as a pair of floating-point values ( x , y ) where the values for x increase as you move rightward across the screen and the values for y increase as you move downward. • If you are familiar with traditional Cartesian geometry, it is important to remember that Java treats y values differently, inverting them from their standard interpretation. Structure of the acm.graphics Package The GObject class forms the root of the hierarchy of graphical objects. Anything you add to the canvas must be a GObject . The classes at the bottom of the figure are the shape classes and indicate specific types of graphical objects that you can draw. The GTurtle and GPen classes provide a simple graphics model appropriate for younger students and are not used in this book. The remaining classes and interfaces are discussed in subsequent slides. The following diagram shows the classes in the acm.graphics package and their relationship in the Java class hierarchy: GCanvas GPoint GDimension GRectangle GObject GCompound GMath GTurtle GPen GLabel GRect GOval GLine GArc GImage GPolygon GRoundRect G3DRect Interfaces: GFillable GResizable GScalable GContainer The GCanvas Class • The GCanvas class is used to represent the background canvas for the collage model and therefore serves as a virtual felt board. When you use the acm.graphics package, you create pictures by adding various GObject s to a GCanvas . • For simple applications, you won’t actually need to work with an explicit GCanvas object. Whenever you run a program that extends GraphicsProgram , the initialization process for the program automatically creates a GCanvas and resizes it so that it fills the program window....
View Full Document

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 62

CH09-ObjectOrientedGraphics - The Art and Science of An...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online