java @ch15. graphics 2011.04.01. outline graphical coodinate systems the graphics class drawing...
Post on 20-Dec-2015
238 views
TRANSCRIPT
Outline
• Graphical Coodinate Systems• The Graphics Class• Drawing Strings, Lines, Rectangles, and Ovals• Drawing Polygons and Polylines
[Sample code]
TestPaintComponent.java
DrawPolyLine.java
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
Drawing Strings, Lines, Rectangles, and Ovals
drawString(String s, int x, int y) method
drawLine(int x1, int y1, int x2, int y2) method
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)
程式練習 :1. 用 g.drawOval() 畫臉2. fillOval() 畫眼睛3. setColor() 設定畫筆顏色4. drawArc() 畫嘴巴
( 需 import java.awt.Color)
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