Download presentation
Presentation is loading. Please wait.
1
Java @Ch15. Graphics 2011.04.01
2
Outline Graphical Coodinate Systems The Graphics Class Drawing Strings, Lines, Rectangles, and Ovals Drawing Polygons and Polylines [Sample code] TestPaintComponent.java DrawPolyLine.java
3
Graphical Coodinate Systems (0,0) at the upper-left corner
4
The Graphics Class Java.awt.Graphics +setColor(color: Color): void +setFont(font: Font): void +drawString(s: String, x: int, y:int): void +drawLine(x1,:int, y1:int, x2:int, y2:int): void +drawRect(x:int, y:int, w:int, h:int): void +fillRect(x:int, y:int, w:int, h:int): void +drawRoundRect(x:int, y:int, w:int, h:int, aw:int, ah:int): void +fillRoundRect(x:int, y:int, w:int, h:int, aw:int, ah:int): void +draw3DRect(x:int, y:int, w:int, h:int, raised:boolean): void +fill3DRect(x:int, y:int, w:int, h:int, raised:boolean): void 課本 P.523
5
Drawing Strings, Lines, Rectangles, and Ovals drawString(String s, int x, int y) method drawLine(int x1, int y1, int x2, int y2) method
6
程式範例 : TestPaintComponent.java 課本 P.524 Liting 15.1
7
drawRec(intx, int y, int w, int h) method fillRec(intx, int y, int w, int h) method
8
drawRoundRect(x, y, w, h, aw, ah) method drawOval(x, y,w, h) method
9
Drawing Arcs drawArc(int x, int y, int w, int h, int startAngle, int arcAngle) fillArc(int x, int y, int w, int h, int startAngle, int arcAngle)
10
範例練習 : DrawArcs.java 課本 P.530 Liting 15.4
11
程式練習 : 1. 用 g.drawOval() 畫臉 2. fillOval() 畫眼睛 3.setColor() 設定畫筆顏色 4. drawArc() 畫嘴巴 ( 需 import java.awt.Color)
12
Drawing Polygons and Polylines Java.awt.Polygon +xpoints: int [] +ypoints: int [] +nponits: int [] +Polygon() +Polygon(xpoints: int [], ypoints: int [], npoints: int []) +addPoints(x: int, y: int) 課本 P.532
13
程式範例 : DrawPolyLine.java
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.