ch03g-1 - Building Java Programs Supplement 3G Graphics...

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

View Full Document Right Arrow Icon
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, 2007.  They may not be  rehosted, sold, or modified without expressed permission from the authors.  All rights reserved.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Lecture outline Drawing 2D graphics DrawingPanel and Graphics objects drawing and filling shapes coordinate system colors drawing with loops drawing with parameterized methods basic animation
Background image of page 2
3 Graphical objects Can draw graphics on screen by interacting with 3 classes of objects: DrawingPanel : A window on the screen. Nnot part of Java; it is provided by the authors. Graphics : A "pen" that can draw shapes and lines onto a window. Color : The colors that indicate what color to draw the shapes.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 DrawingPanel To create a window, construct a DrawingPanel object: DrawingPanel <name> = new DrawingPanel( <width> , <height> ); Example: DrawingPanel panel = new DrawingPanel(300, 200); The window has nothing on it. But we can draw shapes and lines on it using another object of a class named Graphics .
Background image of page 4
5 Graphics Shapes are drawn using an object of class Graphics . Must place an import declaration in your program: import java.awt.*; Access it by calling getGraphics method on your DrawingPanel . Example: Graphics g = panel.getGraphics();
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Graphics Once you have the Graphics object, draw shapes by calling its methods. Example: g.fillRect(10, 30, 60, 35); g.fillOval(80, 40, 50, 70);
Background image of page 6
7 Graphics methods Method name Description drawLine( x1 , y1 , x2 , y2 ) line between points ( x1 , y1 ), ( x2 , y2 ) drawOval( x , y , width , height ) outline of largest oval that fits in a box of size width * height;
Background image of page 7

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

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

This note was uploaded on 11/15/2010 for the course COMPSCI Comp 142 taught by Professor Topham during the Spring '06 term at Shoreline.

Page1 / 28

ch03g-1 - Building Java Programs Supplement 3G Graphics...

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

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