" Graphics & Even Driven Programs ": By: Mahmoud El-Khateeb
" Graphics & Even Driven Programs ": By: Mahmoud El-Khateeb
GCompound GObject
Interfaces:
GFillable
GResizable
GRoundRect G3DRect GScalable
GContainer
GCanvas
add(object) Adds the object to the canvas at the front of the stack
add(object, x, y) Moves the object to (x, y) and then adds it to the canvas
remove(object) Removes the object from the canvas
removeAll() Removes all objects from the canvas
getElementAt(x, y) Returns the frontmost object at (x, y), or null if none
getWidth() Returns the width in pixels of the entire canvas
getHeight() Returns the height in pixels of the entire canvas
setBackground(c) Sets the background color of the canvas to c.
GCompound GObject
GRoundRect G3DRect
Methods Common to All GObjects
setLocation(x, y) Resets the location of the object to the specified point
move(dx, dy) Moves the object dx and dy pixels from its current position
getX() Returns the x coordinate of the object
getY() Returns the y coordinate of the object
getWidth() Returns the horizontal width of the object in pixels
getHeight() Returns the vertical height of the object in pixels
contains(x, y) Returns true if the object contains the specified point
setColor(c) Sets the color of the object to the Color c
getColor() Returns the color currently assigned to the object
setVisible( flag) Sets the visibility flag (false = invisible, true = visible)
isVisible() Returns true if the object is visible
sendToFront() Sends the object to the front of the stacking order
sendToBack() Sends the object to the back of the stacking order
sendForward() Sends the object forward one position in the stacking order
sendBackward() Sends the object backward one position in the stacking order
Methods Defined by Interfaces
• Why Interfaces ?
GFillable (GArc, GOval, GPolygon, GRect)
setFilled( flag) Sets the fill state for the object (false = outlined, true = filled)
isFilled() Returns the fill state for the object
setFillColor(c) Sets the color used to fill the interior of the object to c
getFillColor() Returns the fill color
QuickBrownFox
origin
The quick brown fox jumps ascent
height baseline
over the lazy dog. descent
The GArc Class
• The GArc class represents an arc formed by taking a section from the perimeter
of an oval.
FilledEllipticalArc
Structure of the acm.graphics Package
GCompound GObject
• Looks for the file in the current project directory and then in a
subdirectory named images.
DrawDiamond
skip simulation
Drawing a Diamond (addEdge)
This program draws the same diamond using addEdge:
DrawDiamond
skip simulation
The GCompound class
• The GCompound allows for combining several graphical
objects so they behaves like one GObject.
• General steps:
• General steps: