⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 113-116.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:The Graphical User Interface</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=3//-->
<!--PAGES=113-116//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="109-113.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="116-120.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">The Graphics Class</FONT></H3>
<P>The <I>Graphics</I> class is used to draw lines, shapes, images, and characters. The <I>Graphics</I> class resides in the <I>java.awt</I> package and is an abstract base class. Because it is abstract, it cannot be created by the invocation of <I>new</I>. Instead, it is created by an instance of a <I>Component</I>. The <I>Graphics</I> class has a default coordinate system, as shown in Figure 3.1.</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/03-01.jpg',323,234 )"><IMG SRC="images/03-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/03-01.jpg',323,234)"><FONT COLOR="#000077"><B>Figure 3.1</B></FONT></A>&nbsp;&nbsp;The default coordinate system of the <I>Graphics</I> class.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
public abstract class Graphics &#123;
public abstract Graphics create()
public Graphics create(int x, int y, int width, int height)
public abstract void translate(int x, int y)
public abstract Color getColor()
public abstract void setColor(Color c)
public abstract void setPaintMode()
public abstract void setXORMode(Color c1)
public abstract Font getFont()
public abstract void setFont(Font font)
public FontMetrics getFontMetrics()
public abstract FontMetrics getFontMetrics(Font f)
public abstract Rectangle getClipRect()
public abstract void clipRect(int x, int y, int width, int height)
public abstract void copyArea(int x, int y, int width,  int height, int dx,
int dy)
public abstract void drawLine(int x1, int y1, int x2, int y2)
public abstract void fillRect(int x, int y, int width, int height)
public void drawRect(int x, int y, int width, int height)
public abstract void clearRect(int x, int y, int width, int height)
public abstract void drawRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
public abstract void fillRoundRect(int x, int y, int width, int height,
int arcWidth, int arcHeight)
public void draw3DRect(int x, int y, int width, int height, boolean raised)
public void fill3DRect(int x, int y, int width, int height, boolean raised)
public abstract void drawOval(int x, int y, int width, int height)
public abstract void fillOval(int x, int y, int width, int height)
public abstract void drawArc(int x, int y, int width, int height, int
startAngle, int arcAngle)
public abstract void fillArc(int x, int y, int width, int height,int
startAngle, int arcAngle)
public abstract void drawPolygon(int xPoints[], int yPoints[], int
nPoints)
public void drawPolygon(Polygon p)
public abstract void fillPolygon(int xPoints[], int yPoints[], int
nPoints)
public void fillPolygon(Polygon p)
public abstract void drawString(String str, int x, int y)
public void drawChars(char data[], int offset, int length, int x, int y)
public void drawBytes(byte data[], int offset, int length, int x, int y)
public abstract boolean drawImage(Image img, int x, int y,  ImageObserver
observer)
public abstract boolean drawImage(Image img, int x, int y, int width, int
height, ImageObserver observer)
public abstract boolean drawImage(Image img, int x, int y,  Color
bgcolor, ImageObserver observer)
public abstract boolean drawImage(Image img, int x, int y, int width, int
height,  Color bgcolor, ImageObserver observer)
public abstract void dispose()
public void finalize()
public String toString()
&#125;
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>The <I>Graphics</I> class supports a simple raster graphics package. Suppose the following constants are predefined:</P>
<!-- CODE //-->
<PRE>
Color aColor;
Graphics g;
Rectangle aRectangle;
int x, y, x1, y1, x2, y2;
Boolean raised;
int height, width, arcHeight, arcWidth, nPoint;
int xArray[], yArray[];
char charArray[];
int numberOfItemToDraw, offsetIntoArray;
byte byteArray[];
Image img;
ImageObserver anImageObserver;
</PRE>
<!-- END CODE //-->
<P>To create a graphics instance, use the following:
</P>
<!-- CODE SNIP //-->
<PRE>
Graphics g1 = g.create(x, y, width, height);
</PRE>
<!-- END CODE SNIP //-->
<P>There are color methods for getting and setting the foreground color of the <I>Graphics</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
aColor = g.getColor();
g.setColor(aColor);
</PRE>
<!-- END CODE SNIP //-->
<P>There are paint methods for setting the <I>Graphics</I> instance to overwrite in xor paint mode:</P>
<!-- CODE SNIP //-->
<PRE>
g.setPaintMode();
g.setXORMode(aColor);
</PRE>
<!-- END CODE SNIP //-->
<P>There are clipping methods for shrinking and for getting the clipping rectangle:
</P>
<!-- CODE SNIP //-->
<PRE>
aRectangle = g.getClipRect();
g.clipRect(x, y, width, height);
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>Graphics</I> class supports a method for painting a rectangle with the background color:</P>
<!-- CODE SNIP //-->
<PRE>
clearRect(int x, int y, int width, int height);
</PRE>
<!-- END CODE SNIP //-->
<P>To translate the coordinates of the <I>Graphics</I> instance, use this:</P>
<!-- CODE SNIP //-->
<PRE>
g.translate(x, y);
</PRE>
<!-- END CODE SNIP //-->
<P>To get and set the fonts of the <I>Graphics</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
aFont = g.getFont();
g.setFont(aFont);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the font metrics for a <I>Graphics</I> instance or for a font:</P>
<!-- CODE SNIP //-->
<PRE>
theFontMetrics = g.getFontMetrics();
theFontMetrics = g.getFontMetrics(aFont);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the clipping rectangle:
</P>
<!-- CODE SNIP //-->
<PRE>
aRectangle = g.getClipRect();
</PRE>
<!-- END CODE SNIP //-->
<P>To shrink the clipping rectangle:
</P>
<!-- CODE SNIP //-->
<PRE>
g.clipRect(x, y, width, height);
</PRE>
<!-- END CODE SNIP //-->
<P>To copy and translate a rectangular area of the screen by (dx, dy):
</P>
<!-- CODE SNIP //-->
<PRE>
g.copyArea(x, y, width, height, dx, dy);
</PRE>
<!-- END CODE SNIP //-->
<P>To draw a line between (x1, y1) and (x2, y2):
</P>
<!-- CODE SNIP //-->
<PRE>
g.drawLine(x1, y1, x2, y2);
</PRE>
<!-- END CODE SNIP //-->
<P>To fill a rectangle with the current color:
</P>
<!-- CODE SNIP //-->
<PRE>
g.fillRect(x, y, width, height);
</PRE>
<!-- END CODE SNIP //-->
<P>To draw a rectangle outline with the current color:
</P>
<!-- CODE SNIP //-->
<PRE>
g.drawRect(x, y, width, height);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="109-113.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="116-120.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -