JHTP小结_第十三章_图形及Java2D
2016-08-02 23:40
211 查看
除了最后一节有几个方法,如,GeneralPath(), moveTo(), rotate(), closePath()及translate()没有理解外,其他基本都能理解。
不能理解的部分,权当今后的作业了,因为我要继续前行!Keep moving!
Section 13.1Introduction
• Java’s coordinatesystem (p. 556) is a scheme for identifying every point (p. 567) on the screen.
• A coordinate pair (p.556) has an
x-coordinate (horizontal) and a
y-coordinate(vertical).
• Coordinates are used toindicate where graphics should be displayed on a screen.
• Coordinate units are measuredin pixels (p. 556). A pixel is a display monitor’s smallest unit of resolution.
Section 13.2Graphics Contexts and Graphics Objects
• A Java graphics context(p. 558) enables drawing on the screen.
• Class
Graphics
(p. 558)contains methods for drawing strings, lines, rectangles and other shapes.
Methods are also includedfor font manipulation and color manipulation.
• A
Graphics
objectmanages a graphics context and draws pixels on the screen that represent text andother graphical objects, e.g., lines, ellipses, rectangles and other polygons(p.
558).
• Class
Graphics
is an
abstract
class. EachJava implementation has a
Graphics
subclass that provides drawing capabilities. This implementationis hidden from us by class
Graphics, which supplies theinterface that enables us to use graphics
in a platform-independent manner.
• Method
paintComponentcan be used to draw graphics in any
JComponentcomponent.
• Method
paintComponentreceives a
Graphics
object that is passed to the method by the system when alightweight Swing component needs to be repainted.
• When an applicationexecutes, the application container calls method
paintComponent. For
paintComponentto be called again, an event must occur.
• When a
JComponentis displayed, its
paintComponent
method iscalled.
• Calling method
repaint
(p. 559) on acomponent updates the graphics drawn on that component.
Section 13.3 ColorControl
• Class
Color
(p. 559)declares methods and constants for manipulating colors in a Java program.
• Every color is createdfrom a red, a green and a blue component. Together these components are calledRGB values (p. 560). The RGB components specify the
amount of red, green andblue in a color, respectively. The larger the value, the greater the amount ofthat particular color.
•
Color
methods
getRed,
getGreen
and
getBlue
(p. 560)return
int
values from 0 to 255 representing the amount of red, green andblue, respectively.
•
Graphics
method
getColor
(p. 560)returns a
Color
object with the current drawing color.
•
Graphics
method
setColor
(p. 560) setsthe current drawing color.
•
Graphics
method
fillRect
(p. 560)draws a rectangle filled by the
Graphics
object’s current color.
•
Graphics
method
drawString(p. 562) draws a
String
in the current color.
• The
JColorChooserGUI component (p. 563) enables application users to
selectcolors.
•
JColorChooserstatic
method
showDialog
(p. 564) displays a modal
JColorChooser
dialog.
Section 13.4Manipulating Fonts
• Class
Font
(p. 566)contains methods and constants for manipulating fonts.
• Class
Font’sconstructor takes three arguments—the font name (p. 567),
font styleand font size.
• A
Font’s font stylecan be
Font.PLAIN,
Font.ITALIC
or
Font.BOLD
(each is a
static
field of class
Font). Font styles can beused in combination (e.g.,
Font.ITALIC + Font.BOLD).
• The font size ismeasured in points. A point is 1/72 of an inch.
•
Graphics
method
setFont
(p. 567) setsthe drawing font in which text will be displayed.
•
Font
method
getSize
(p. 567)returns the font size in points.
•
Font
method
getName
(p. 567)returns the current font name as a string.
•
Font
method
getStyle
(p. 569)returns an integer value representing the current
Font’s style.
•
Font
method
getFamily
(p. 569)returns the name of the font family to which
the current font belongs. The nameof the font family is platform specific.
• Class
FontMetrics(p. 569) contains methods for obtaining font information.
• Font metrics (p. 569)include height, descent and leading.
Section 13.5Drawing Lines, Rectangles and Ovals
•
Graphics
methods
fillRoundRect(p. 573) and
drawRoundRect
(p. 573) drawrectangles with rounded corners.
•
Graphics
methods
draw3DRect(p. 575) and
fill3DRect
(p. 575) drawthree-dimensional rectangles.
•
Graphics
methods
drawOval
(p. 575) and
fillOval
(p. 575) drawovals.
Section 13.6Drawing Arcs
• An arc (p. 575) isdrawn as a portion of an oval.
• Arcs sweep from astarting angle by the number of degrees specified by their arc angle (p. 575).
•
Graphics
methods
drawArc
(p. 575) and
fillArc
(p. 575) areused for drawing arcs.
Section 13.7Drawing Polygons and Polylines
• Class
Polygon
containsmethods for creating polygons
• Polygons are closedmultisided shapes composed of straight-line segments.
• Polylines (p. 578) aresequences of connected points.
•
Graphics
method
drawPolyline(p. 580) displays a series of connected lines.
•
Graphics
methods
drawPolygon(p. 580) and
fillPolygon
(p. 581) are used to drawpolygons.
•
Polygon
method
addPoint
(p. 581) addspairs of
x- and
y-coordinates to the
Polygon.
Section 13.8 Java2D API
• The Java 2D API (p.581) provides advanced two-dimensional graphics capabilities.
• Class
Graphics2D(p. 581)—a subclass of
Graphics—is used fordrawing with the Java 2D API.
• The Java 2D API’sclasses for drawing shapes include
Line2D.Double,
Rectangle2D.Double,
RoundRectangle2D.Double,
Arc2D.Doubleand
Ellipse2D.Double
(p. 581).
• Class
GradientPaint(p. 584) helps draw a shape in gradually changing
colors—calleda gradient(p. 584).
•
Graphics2Dmethod
fill
(p. 584) draws a filled object of any type that implementsinterface
Shape (p. 584).
• Class
BasicStroke(p. 584) helps specify the drawing characteristics of
lines.
•
Graphics2Dmethod
draw
(p. 584) is used to draw a
Shape
object.
• Classes
GradientPaint(p. 584) and
TexturePaint
(p. 585) help specify thecharacteristics for filling shapes with colors or patterns.
• A general path (p. 586)is a shape constructed from straight lines and complex curves and isrepresented with an object of class
GeneralPath
(p. 586).
•
GeneralPathmethod
moveTo
(p. 587) specifies the first point in a general path.
•
GeneralPathmethod
lineTo
(p. 588) draws a line to the next point in the path. Each newcall to
lineTo
draws a line from the previous point to the current point.
•
GeneralPathmethod
closePath
(p. 588) draws a line from the last point to the point specifiedin the last call to
moveTo. This completes the general path.
•
Graphics2Dmethod
translate
(p. 588) is used to move the drawing origin to a new location.
•
Graphics2D
method
rotate
(p. 588) is used to rotate the next displayed shape.
不能理解的部分,权当今后的作业了,因为我要继续前行!Keep moving!
Section 13.1Introduction
• Java’s coordinatesystem (p. 556) is a scheme for identifying every point (p. 567) on the screen.
• A coordinate pair (p.556) has an
x-coordinate (horizontal) and a
y-coordinate(vertical).
• Coordinates are used toindicate where graphics should be displayed on a screen.
• Coordinate units are measuredin pixels (p. 556). A pixel is a display monitor’s smallest unit of resolution.
Section 13.2Graphics Contexts and Graphics Objects
• A Java graphics context(p. 558) enables drawing on the screen.
• Class
Graphics
(p. 558)contains methods for drawing strings, lines, rectangles and other shapes.
Methods are also includedfor font manipulation and color manipulation.
• A
Graphics
objectmanages a graphics context and draws pixels on the screen that represent text andother graphical objects, e.g., lines, ellipses, rectangles and other polygons(p.
558).
• Class
Graphics
is an
abstract
class. EachJava implementation has a
Graphics
subclass that provides drawing capabilities. This implementationis hidden from us by class
Graphics, which supplies theinterface that enables us to use graphics
in a platform-independent manner.
• Method
paintComponentcan be used to draw graphics in any
JComponentcomponent.
• Method
paintComponentreceives a
Graphics
object that is passed to the method by the system when alightweight Swing component needs to be repainted.
• When an applicationexecutes, the application container calls method
paintComponent. For
paintComponentto be called again, an event must occur.
• When a
JComponentis displayed, its
paintComponent
method iscalled.
• Calling method
repaint
(p. 559) on acomponent updates the graphics drawn on that component.
Section 13.3 ColorControl
• Class
Color
(p. 559)declares methods and constants for manipulating colors in a Java program.
• Every color is createdfrom a red, a green and a blue component. Together these components are calledRGB values (p. 560). The RGB components specify the
amount of red, green andblue in a color, respectively. The larger the value, the greater the amount ofthat particular color.
•
Color
methods
getRed,
getGreen
and
getBlue
(p. 560)return
int
values from 0 to 255 representing the amount of red, green andblue, respectively.
•
Graphics
method
getColor
(p. 560)returns a
Color
object with the current drawing color.
•
Graphics
method
setColor
(p. 560) setsthe current drawing color.
•
Graphics
method
fillRect
(p. 560)draws a rectangle filled by the
Graphics
object’s current color.
•
Graphics
method
drawString(p. 562) draws a
String
in the current color.
• The
JColorChooserGUI component (p. 563) enables application users to
selectcolors.
•
JColorChooserstatic
method
showDialog
(p. 564) displays a modal
JColorChooser
dialog.
Section 13.4Manipulating Fonts
• Class
Font
(p. 566)contains methods and constants for manipulating fonts.
• Class
Font’sconstructor takes three arguments—the font name (p. 567),
font styleand font size.
• A
Font’s font stylecan be
Font.PLAIN,
Font.ITALIC
or
Font.BOLD
(each is a
static
field of class
Font). Font styles can beused in combination (e.g.,
Font.ITALIC + Font.BOLD).
• The font size ismeasured in points. A point is 1/72 of an inch.
•
Graphics
method
setFont
(p. 567) setsthe drawing font in which text will be displayed.
•
Font
method
getSize
(p. 567)returns the font size in points.
•
Font
method
getName
(p. 567)returns the current font name as a string.
•
Font
method
getStyle
(p. 569)returns an integer value representing the current
Font’s style.
•
Font
method
getFamily
(p. 569)returns the name of the font family to which
the current font belongs. The nameof the font family is platform specific.
• Class
FontMetrics(p. 569) contains methods for obtaining font information.
• Font metrics (p. 569)include height, descent and leading.
Section 13.5Drawing Lines, Rectangles and Ovals
•
Graphics
methods
fillRoundRect(p. 573) and
drawRoundRect
(p. 573) drawrectangles with rounded corners.
•
Graphics
methods
draw3DRect(p. 575) and
fill3DRect
(p. 575) drawthree-dimensional rectangles.
•
Graphics
methods
drawOval
(p. 575) and
fillOval
(p. 575) drawovals.
Section 13.6Drawing Arcs
• An arc (p. 575) isdrawn as a portion of an oval.
• Arcs sweep from astarting angle by the number of degrees specified by their arc angle (p. 575).
•
Graphics
methods
drawArc
(p. 575) and
fillArc
(p. 575) areused for drawing arcs.
Section 13.7Drawing Polygons and Polylines
• Class
Polygon
containsmethods for creating polygons
• Polygons are closedmultisided shapes composed of straight-line segments.
• Polylines (p. 578) aresequences of connected points.
•
Graphics
method
drawPolyline(p. 580) displays a series of connected lines.
•
Graphics
methods
drawPolygon(p. 580) and
fillPolygon
(p. 581) are used to drawpolygons.
•
Polygon
method
addPoint
(p. 581) addspairs of
x- and
y-coordinates to the
Polygon.
Section 13.8 Java2D API
• The Java 2D API (p.581) provides advanced two-dimensional graphics capabilities.
• Class
Graphics2D(p. 581)—a subclass of
Graphics—is used fordrawing with the Java 2D API.
• The Java 2D API’sclasses for drawing shapes include
Line2D.Double,
Rectangle2D.Double,
RoundRectangle2D.Double,
Arc2D.Doubleand
Ellipse2D.Double
(p. 581).
• Class
GradientPaint(p. 584) helps draw a shape in gradually changing
colors—calleda gradient(p. 584).
•
Graphics2Dmethod
fill
(p. 584) draws a filled object of any type that implementsinterface
Shape (p. 584).
• Class
BasicStroke(p. 584) helps specify the drawing characteristics of
lines.
•
Graphics2Dmethod
draw
(p. 584) is used to draw a
Shape
object.
• Classes
GradientPaint(p. 584) and
TexturePaint
(p. 585) help specify thecharacteristics for filling shapes with colors or patterns.
• A general path (p. 586)is a shape constructed from straight lines and complex curves and isrepresented with an object of class
GeneralPath
(p. 586).
•
GeneralPathmethod
moveTo
(p. 587) specifies the first point in a general path.
•
GeneralPathmethod
lineTo
(p. 588) draws a line to the next point in the path. Each newcall to
lineTo
draws a line from the previous point to the current point.
•
GeneralPathmethod
closePath
(p. 588) draws a line from the last point to the point specifiedin the last call to
moveTo. This completes the general path.
•
Graphics2Dmethod
translate
(p. 588) is used to move the drawing origin to a new location.
•
Graphics2D
method
rotate
(p. 588) is used to rotate the next displayed shape.
相关文章推荐
- JHTP自测题_第十三章_图形及Java2D
- 图形与java2D小结与经验
- J2ME移动2D图形开发快速入门-Java基础-Java-编程开发
- java图形处理-Java 2D
- java gui处理2D图形
- java2d图形设备的几个基本类
- Java中2D图形常用方法
- JHTP小结_第二章_Java应用、输入、输出及运算符简介
- 创建Java2D图形
- Java学习笔记--Swing2D图形
- java-第十三章-类的无参方法(一)-实现图形生成器
- java图形处理-Java 2D
- 你应该知道的 - 关于 Java 2D 中图形上下文基类 Graphics(转)
- Java图形设计中,利用Bresenham算法实现直线线型,线宽的控制(NO 2D GRAPHICS)
- 小结:基本绘制图形知识点(Quartz2D第一天)
- 小结:基本绘制图形知识点(Quartz2D第二天)
- java 2D图形绘制
- Swing图形编程---------Java2D
- java学习笔记图形程序设计及GUI应用小结(3)
- 你应该知道的 - 关于 Java 2D 中图形上下文基类 Graphics