3D教案13.ppt
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
§10.2, “Abstract Classes,” in Chapter 10 §10.4, “Interfaces,” in Chapter 10
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6
3
百度文库
Each GUI Component Has its Own Coordinate System
(c3.getX(), c3c.3g.egteYtX()())
(x, y) (0, 0)
Component c3
(c2.getX(), c2.getY())
(c1.getX(), c1.getY())
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6
2
Java Coordinate System
x (0, 0)
Draws a rectangle with specified upper-left corner point at (x, y) and width w and height h.
+fillRect(x: int, y: int, w: int, h: int): void
Draws a filled rectangle with specified upper-left corner point at (x, y) and width w and height h.
X Axis
y Y Axis
(x, y)
Java Coordinate System
Y Axis
Conventional Coordinate System
(0, 0)
X Axis
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6
Draws a string starting at point (x, y).
+drawLine(x1: int, y1: int, x2: int, y2: int): void Draws a line from (x1, y1) to (x2, y2).
+drawRect(x: int, y: int, w: int, h: int): void
1
Objectives
To understand Java coordinate systems (§13.2). To draw things using the methods in the Graphics class (§13.3). To obtain a graphics context using the getGraphics() method (§13.3). To override the paintComponent method to draw things on a graphical context (§13.4). To use a panel as a canvas to draw things (§13.5). To draw strings, lines, rectangles, ovals, arcs, and polygons (§§13.6, 13.8-13.9). To obtain font properties using FontMetrics and know how to center a message (§13.10). To display image in a GUI component (§13.13). To develop reusable GUI components FigurePanel, MessagePanel, StillClock, and ImageViewer (§§13.7, 13.11, 13.12, 13.14).
4
The Graphics Class
You can draw strings, lines, rectangles, ovals, arcs, polygons, and polylines, using the methods in the Graphics class.
java.awt.Graphics
+setColor(color: Color): void
Sets a new color for subsequent drawings.
+setFont(font: Font): void
Sets a new font for subsequent drwings.
+drawString(s: String, x: int, y: int): void
Chapter 13 Graphics
Chapter 12 GUI Basics Chapter 13 Graphics Chapter 14 Event-Driven Programming Chapter 15 Creating User Interfaces Chapter 16 Applets and Multimedia
(x, y) (0, 0) (x, y) (0, 0)
Component c2 Component c1
c3’s coordinate system
c2’s coordinate system
c1’s coordinate system
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved. 0-13-222158-6