Save
Java2
Ch13
Save
Share
Learn
Content
Leaderboard
Learn
Created by
tesst t
Visit profile
Cards (44)
Computer graphics
Generating
2D
images of a
3D
world represented in a computer
Main tasks in Graphics
Modeling (
shape
): creating and representing the geometry of
objects
in the 3D world
Rendering (
light
,
perspective
): generating 2D images of objects
Animation (movement): describing how objects
change
in
time
Representations in Graphics
Vector Graphics
: Image is represented by
continuous
geometric objects: lines, curves, etc.
Raster Graphics
: Image is represented as a
rectangular grid
of colored pixels
World Coordinates
Center is (
0,0
)
Screen Coordinates
Upper-left corner
is (
0
,0)
Applications of Computer Graphics
Entertainment: animated movies, etc.
Medical Visualization
Educational Training
Game Modeling & Simulation
Graphical User Interfaces (GUI)
Computer Aided Design (CAD)
Scientific Visualization
Other tasks in Graphics
Image processing
techniques: Edge Detection, Image De-noising, Object Detection
Geometric Transformations
: Translation, Rotation, Scaling, Clipping
More
advanced operations
: Hidden surface algorithms, Representing 3D shapes, Displaying depth relationships, Shading, reflection, ambient lighting
Graphics Class in Java
paint()
or paintComponent() is passed a reference to a
Graphics object
A
Graphics object
is a device-independent interface to the computer's
graphics
display
Most of its methods are concerned with drawing shapes (filled and unfilled), and managing
fonts
and
colours
Put your own graphics on the screen
1. Create your own
paintable
widget
2. Put the widget on the frame
3.
Display
it
GUI component
An object that can be represented visually on the
computer screen
and can be acted upon by a
human user
Rendering
The process of
transforming
the
GUI
component's internal data into a visual image
Graphics context object
Holds the data needed to do the
transformation
of a GUI component's
internal
data into a visual image
java.awt.Graphics
The abstract
superclass
for all graphics context
objects
in Java
Component Class
Superclass
for many classes in java.awt package
Method
paint()
takes Graphics object as an
argument
repaint()
calls
update()
, which forces a paint() operation
Class
Color
Defines
methods
and constants for
manipulating
colors
Colors created from red,
green
, and
blue
(RGB) components
JColorChooser
Used to create a color chooser
dialog box
so that user can select any color
showDialog() returns a
Color
object
Class Font
States
fonts
, which are used to render
text
in a visible way
Constructor: creates a new Font from the specified
font
, and it takes three arguments: name, style,
size
Font Methods
getStyle()
getSize()
getName()
getFamily()
getFont()
isPlain()
isBold()
isItalic()
setFont(Font f)
isItalic()
Indicates whether or not this Font object's style is
ITALIC
setFont
(
Font f
)
Is used to set the graphics
current
font to the
specified
font
Font
Represents a font face,
size
, and
style
Font
BOLD
ITALIC
PLAIN
Font types
Serif
Monospaced
SansSerif
FontMetrics
Has methods for getting font
metrics
g.getFontMetrics
()
Returns FontMetrics
object
Ascent
The distance this string
extends
above the
baseline
Descent
The distance this string descends below the
baseline
Leading
The standard leading of the Font
Height
The standard height of a
line
of
text
in this font
g.getFontMetrics
(Font
f
)
drawLine(x1, y1, x2, y2)
Draws a Line from (x1,
y1
) to (
x2
, y2)
drawRect(x1, y1, width, height)
Draws a
rectangle
with upper left corner (x1,
y1
)
draw3DRect
(x1, y1, width, height, isRaised)
Draws 3D
rectangle
, raised if isRaised is true, else
lowered
fill3DRect
(x, y, width, height, raised)
Paints
a
3-D
highlighted rectangle filled with the current color
drawRoundRect(x, y, width, height, arcWidth, arcHeight)
Draws
rectangle
with
rounded corners
fillOval
(x, y, width, height)
Fills an
oval
bounded by the specified
rectangle
with the current color
drawArc(x, y, width, height, startAngle, arcAngle)
Draws a
circular
or
elliptical
arc
drawPolygon(
xPoints
[],
yPoints
[], points)
Draws a polygon, with x and y
points
specified in
arrays
drawPolyline(
xPoints
[],
yPoints
[], points)
Draws a polyline, a series of connected
points
See all 44 cards