📄 146-150.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=146-150//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="142-145.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="150-155.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading30"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose that the following variables are defined:
</P>
<!-- CODE //-->
<PRE>
Component comp, compArray[];
Container cont;
Insets insets;
int ncomponents, i;
String layoutName; // the name of a layout manager.
LayoutManager layMan;
Graphics gc;
int x,y;
PrintStream printStream;
int indent;
</PRE>
<!-- END CODE //-->
<P>To get the number of components use this statement:
</P>
<!-- CODE SNIP //-->
<PRE>
ncomponents = comp.countComponents();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the <I>n</I>th component:</P>
<!-- CODE SNIP //-->
<PRE>
comp = cont.getComponent(i);
</PRE>
<!-- END CODE SNIP //-->
<P>To get all the components:
</P>
<!-- CODE SNIP //-->
<PRE>
compArray = cont.getComponents();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the insets (rectangular dimensions in pixels from the edges):
</P>
<!-- CODE SNIP //-->
<PRE>
insets = cont.insets();
i = insets.bottom;
i = insets.top;
i = insets.left;
i = insets.right;
</PRE>
<!-- END CODE SNIP //-->
<P>To add a <I>Component</I> to a <I>Container</I>:</P>
<!-- CODE SNIP //-->
<PRE>
cont.add(comp);
</PRE>
<!-- END CODE SNIP //-->
<P>To add a <I>Component</I> to a <I>Container</I> in a given order (-1 means end of list):</P>
<!-- CODE SNIP //-->
<PRE>
cont.add(comp, i);
</PRE>
<!-- END CODE SNIP //-->
<P>To add a <I>Component</I> to a <I>Container</I> using a layout manager:</P>
<!-- CODE SNIP //-->
<PRE>
cont.add(layoutName, i);
</PRE>
<!-- END CODE SNIP //-->
<P>To remove a <I>Component</I> from a <I>Container</I>:</P>
<!-- CODE SNIP //-->
<PRE>
cont.remove(comp);
</PRE>
<!-- END CODE SNIP //-->
<P>To delete all <I>Components</I>:</P>
<!-- CODE SNIP //-->
<PRE>
cont.removeAll();
</PRE>
<!-- END CODE SNIP //-->
<P>To get and set the layout manager:
</P>
<!-- CODE SNIP //-->
<PRE>
layMan = cont.getLayout();
cont.setLayout(layMan);
</PRE>
<!-- END CODE SNIP //-->
<P>To perform layout on the <I>Container</I> but not the descendants:</P>
<!-- CODE SNIP //-->
<PRE>
cont.layout();
</PRE>
<!-- END CODE SNIP //-->
<P>To perform layout on the <I>Container</I> and all descendants:</P>
<!-- CODE SNIP //-->
<PRE>
cont.validate();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the preferred and minimum dimensions:
</P>
<!-- CODE SNIP //-->
<PRE>
Dimension dim = cont.preferredSize();
dim cont.minimumSize();
</PRE>
<!-- END CODE SNIP //-->
<P>To paint or print the <I>Components</I> onto a <I>Graphics</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
cont.paintComponents(gc);
cont.printComponents(gc);
</PRE>
<!-- END CODE SNIP //-->
<P>From within a <I>Container</I> (such as a <I>Frame</I>) you can write the following:</P>
<!-- CODE SNIP //-->
<PRE>
printComponents(getGraphics());
paintComponents(getGraphics());
</PRE>
<!-- END CODE SNIP //-->
<P>To post an <I>Event</I> to a <I>Component</I> located at (e.x, e.y):</P>
<!-- CODE SNIP //-->
<PRE>
Event e;
cont.deliverEvent(e);
</PRE>
<!-- END CODE SNIP //-->
<P>To locate a component at (x, y):
</P>
<!-- CODE SNIP //-->
<PRE>
comp = cont.locate(x, y); // null returned if compoent unfound
</PRE>
<!-- END CODE SNIP //-->
<P>To send the <I>addNotify</I> message to all descendents and the superclass:</P>
<!-- CODE SNIP //-->
<PRE>
cont.addNotify(); // this creates peer descendents
</PRE>
<!-- END CODE SNIP //-->
<P>To send the <I>removeNotify</I> message to all descendents and the superclass:</P>
<!-- CODE SNIP //-->
<PRE>
cont.removeNotify(); // this deletes peer descendents
</PRE>
<!-- END CODE SNIP //-->
<P>To print a list of the descendents:
</P>
<!-- CODE SNIP //-->
<PRE>
cont.list(printStream, indent);
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>indent</I> is the indentation used during generation traversal. For example, in <I>AudioFrame.java</I>, a <I>MenuItem</I> event is handled by the following:</P>
<!-- CODE SNIP //-->
<PRE>
if (Evt.match(e,print_mi)) {
validate();
list(System.out,5);
return true;
}
</PRE>
<!-- END CODE SNIP //-->
<P>The preceding code emits a component list, including four Scroll bars, a panel, a label, and an <I>intLabel</I>:</P>
<!-- CODE //-->
<PRE>
lyon.AudioFrame[0,0,550x385,layout=java.awt.BorderLayout,
title=/hd/current/Java%20book/code/au/ah.au]
java.awt.Scrollbar[0,0,550x16,val=14,vis=true,min=0,max=24,horz]
java.awt.Scrollbar[0,354,550x16,val=0,vis=true,min=0,max=3469,horz]
java.awt.Scrollbar[0,23,16x331,val=0,vis=true,min=-300,max=300,vert]
java.awt.Scrollbar[534,23,16x331,val=8,vis=true,min=0,max=11,vert]
java.awt.Panel[0,0,550x23,layout=java.awt.FlowLayout]
java.awt.Label[206,5,101x13,align=left,label=Number of Samples:]
lyon.IntLabel[312,5,32x13,align=left,label=3469]
</PRE>
<!-- END CODE //-->
<P>This list can be useful for debugging purposes. The <I>Frame</I> instance is shown in Figure 3.8.</P>
<P><A NAME="Fig8"></A><A HREF="javascript:displayWindow('images/03-08.jpg',548,403 )"><IMG SRC="images/03-08t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/03-08.jpg',548,403)"><FONT COLOR="#000077"><B>Figure 3.8</B></FONT></A> The digital oscilloscope.</P>
<H3><A NAME="Heading31"></A><FONT COLOR="#000077">The Frame Class</FONT></H3>
<P>The <I>Frame</I> class is a descendent of the <I>Window</I> class (which in turn descends from the <I>Container</I> and <I>Component</I> classes). As an extension of the <I>Window</I> class, the <I>Frame</I> class adds a title bar, menu bar, border, cursor, and icon image. <I>Frame</I> implements <I>MenuContainer</I> and so can contain <I>MenuComponents</I>.</P>
<H4 ALIGN="LEFT"><A NAME="Heading32"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
package java.awt;
public class Frame extends Window implements MenuContainer
public static final int DEFAULT_CURSOR
public static final int CROSSHAIR_CURSOR
public static final int TEXT_CURSOR
public static final int WAIT_CURSOR
public static final int SW_RESIZE_CURSOR
public static final int SE_RESIZE_CURSOR
public static final int NW_RESIZE_CURSOR
public static final int NE_RESIZE_CURSOR
public static final int N_RESIZE_CURSOR
public static final int S_RESIZE_CURSOR
public static final int W_RESIZE_CURSOR
public static final int E_RESIZE_CURSOR
public static final int HAND_CURSOR
public static final int MOVE_CURSOR
public Frame()
public Frame(String title)
public synchronized void addNotify()
public String getTitle()
public void setTitle(String title)
public Image getIconImage()
public void setIconImage(Image image)
public MenuBar getMenuBar()
public synchronized void setMenuBar(MenuBar mb)
public synchronized void remove(MenuComponent m)
public synchronized void dispose()
public boolean isResizable()
public void setResizable(boolean resizable)
public void setCursor(int cursorType)
public int getCursorType()
}
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="142-145.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="150-155.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright © <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 + -