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

📄 138-142.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=138-142//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="135-138.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="142-145.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading27"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>We use the term <I>peer</I> to indicate the parallel that exists in the native implementation of a component. For example, <I>FileDialog</I> is a subclass of a <I>Component</I> that has a different implementation on every platform. To provide an API that looks the same on all platforms, Java uses a peer class that provides the services needed to allow the API to function properly. This means that the Open dialog box created on a Macintosh is the standard File Open dialog box that is supplied by the operating system. Also, the Open dialog box on a Windows system is the Load File dialog box that is native to Windows. Peers are the mechanism by which Java achieves a portable operating system interface.</P>
<P>Suppose the following variables are defined:</P>
<!-- CODE //-->
<PRE>
Container parent;
int x,y;
int width, height;
Color foreground, background;
Font font;
boolean visible = true;
boolean enabled = true;
boolean valid = false;
Component component;
ComponentPeer componentPeer;
Dimension aDimension;
Graphics graphics;
Image anImage;
Boolean aBoolean;
int flags, indent;
ImageProducer anImageProducer;
</PRE>
<!-- END CODE //-->
<P>To get the parent of the component, use this code:
</P>
<!-- CODE SNIP //-->
<PRE>
parent = component.getParent();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the peer of the component:
</P>
<!-- CODE SNIP //-->
<PRE>
componentPeer = component.getPeer();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the toolkit used by the component (see the <I>Toolkit</I> class):</P>
<!-- CODE SNIP //-->
<PRE>
toolKit = component.getToolkit();
</PRE>
<!-- END CODE SNIP //-->
<P>To see whether the peer is known to the component and whether the component is properly laid out:
</P>
<!-- CODE SNIP //-->
<PRE>
valid = component.isValid();
</PRE>
<!-- END CODE SNIP //-->
<P>To see whether the Component is visible (the <I>hide</I> method can make this statement return false):</P>
<!-- CODE SNIP //-->
<PRE>
visible = component.isVisible();
</PRE>
<!-- END CODE SNIP //-->
<P>Visible components may not be showing:
</P>
<!-- CODE SNIP //-->
<PRE>
visible = component.isShowing();
</PRE>
<!-- END CODE SNIP //-->
<P>Enabled components can generate events:
</P>
<!-- CODE SNIP //-->
<PRE>
aBoolean = isEnabled();
</PRE>
<!-- END CODE SNIP //-->
<P>To unconditionally enable a component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.enable();
</PRE>
<!-- END CODE SNIP //-->
<P>To conditionally enable a component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.enable(cond);
</PRE>
<!-- END CODE SNIP //-->
<P>To disable a component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.disable();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the location of the component relative to the parent&#146;s coordinate system:
</P>
<!-- CODE SNIP //-->
<PRE>
aPoint = component.location();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the dimensions and bounds of the component:
</P>
<!-- CODE SNIP //-->
<PRE>
aDimension = component.size();
aRectangle = component.bounds();
</PRE>
<!-- END CODE SNIP //-->
<P>To show the component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.show();
</PRE>
<!-- END CODE SNIP //-->
<P>To conditionally show the component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.show(cond);
</PRE>
<!-- END CODE SNIP //-->
<P>To hide the component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.hide();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the component&#146;s foreground color (or that of its parent):
</P>
<!-- CODE SNIP //-->
<PRE>
aColor = component.getForeground();
</PRE>
<!-- END CODE SNIP //-->
<P>To set the component&#146;s foreground color:
</P>
<!-- CODE SNIP //-->
<PRE>
component.setForeground(aColor);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the component&#146;s background color (or that of its parent):
</P>
<!-- CODE SNIP //-->
<PRE>
aColor = component.getBackground();
</PRE>
<!-- END CODE SNIP //-->
<P>To set the component&#146;s background color:
</P>
<!-- CODE SNIP //-->
<PRE>
component.setBackground(aColor);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the font from a component or that of its parent if the component does not have one set:
</P>
<!-- CODE SNIP //-->
<PRE>
font = component.getFont();
</PRE>
<!-- END CODE SNIP //-->
<P>To set the font of a component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.setFont(font);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the <I>ColorModel</I> used for display:</P>
<!-- CODE SNIP //-->
<PRE>
colorModel = component.getColorModel();
</PRE>
<!-- END CODE SNIP //-->
<P>To move the component using the parent&#146;s coordinate system:
</P>
<!-- CODE SNIP //-->
<PRE>
component.move(x, y);
</PRE>
<!-- END CODE SNIP //-->
<P>To resize the component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.resize(width, height);
component.resize(aDimension);
</PRE>
<!-- END CODE SNIP //-->
<P>To reshape (resize and move) a component, in the parent&#146;s coordinates:
</P>
<!-- CODE SNIP //-->
<PRE>
component.reshape(x, y, width, height);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the preferred or minimum dimensions for the component:
</P>
<!-- CODE SNIP //-->
<PRE>
aDimension = component.preferredSize();
aDimension = component.minimumSize();
</PRE>
<!-- END CODE SNIP //-->
<P>To lay out the component (typically, <I>validate</I> is used):</P>
<!-- CODE SNIP //-->
<PRE>
component.layout();
</PRE>
<!-- END CODE SNIP //-->
<P>To lay out the component and make the component valid:
</P>
<!-- CODE SNIP //-->
<PRE>
component.validate();
</PRE>
<!-- END CODE SNIP //-->
<P>To invalidate a component and its parent (marking for layout):
</P>
<!-- CODE SNIP //-->
<PRE>
component.invalidate();
</PRE>
<!-- END CODE SNIP //-->
<P>To get a <I>Graphics</I> context for the component (and to return <I>null</I> if there is no peer):</P>
<!-- CODE SNIP //-->
<PRE>
component.getGraphics();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the font metrics for the component&#146;s peer, if available, otherwise returning the font metrics for the component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.getFontMetrics(font);
</PRE>
<!-- END CODE SNIP //-->
<P>To paint the component:
</P>
<!-- CODE SNIP //-->
<PRE>
component.paint(graphics);
</PRE>
<!-- END CODE SNIP //-->
<P>To update the component (typically called by <I>repaint</I>):</P>
<!-- CODE SNIP //-->
<PRE>
component.update(graphics);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="135-138.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="142-145.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 + -