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

📄 155-160.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=155-160//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="150-155.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="160-164.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading40"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
public class Checkbox extends Component &#123;
 public Checkbox()
 public Checkbox(String label)
 public Checkbox(String label, CheckboxGroup group, boolean state)
 public synchronized void addNotify()
 public String getLabel()
 public void setLabel(String label)
 public boolean getState()
 public void setState(boolean state)
 public CheckboxGroup getCheckboxGroup()
 public void setCheckboxGroup(CheckboxGroup g)
&#125;
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading41"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
String label;
CheckboxGroup group;
boolean state;
Checkbox cb;
</PRE>
<!-- END CODE SNIP //-->
<P>To make an instance of an unchecked <I>Checkbox</I> without a label or group, use this statement:</P>
<!-- CODE SNIP //-->
<PRE>
cb = new Checkbox();
</PRE>
<!-- END CODE SNIP //-->
<P>To make an instance of an unchecked <I>Checkbox</I> with a label and no group:</P>
<!-- CODE SNIP //-->
<PRE>
cb = new Checkbox(label);
</PRE>
<!-- END CODE SNIP //-->
<P>To make an instance of a <I>Checkbox</I> with a label, group, and known state:</P>
<!-- CODE SNIP //-->
<PRE>
cb = new Checkbox(label, group, state);
</PRE>
<!-- END CODE SNIP //-->
<P>To make the peer of a <I>Checkbox</I>:</P>
<!-- CODE SNIP //-->
<PRE>
cb.addNotify();
</PRE>
<!-- END CODE SNIP //-->
<P>To get and set the label of a <I>Checkbox</I>:</P>
<!-- CODE SNIP //-->
<PRE>
label = cb.getLabel();
cb.setLabel(label);
</PRE>
<!-- END CODE SNIP //-->
<P>To get and set the state of the <I>Checkbox</I>:</P>
<!-- CODE SNIP //-->
<PRE>
state = cb.getState();
cb.setState(state);
</PRE>
<!-- END CODE SNIP //-->
<P>To get and set the group of the <I>Checkbox</I>:</P>
<!-- CODE SNIP //-->
<PRE>
group = cb.getCheckboxGroup();
cb.setCheckboxGroup(group);
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading42"></A><FONT COLOR="#000077">Adding Check Boxes to Frames</FONT></H4>
<P>In <I>GUI.java</I>, the check boxes for the DiffCAD frame are placed into an array of check boxes. The array is used to manipulate the check boxes with fewer lines of code. The check boxes are shown in Figure 3.10, the DiffCAD main frame.</P>
<P><A NAME="Fig10"></A><A HREF="javascript:displayWindow('images/03-10.jpg',279,272 )"><IMG SRC="images/03-10t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/03-10.jpg',279,272)"><FONT COLOR="#000077"><B>Figure 3.10</B></FONT></A>&nbsp;&nbsp;The DiffCAD main frame. Note the Vector Pict File output.</P>
<!-- CODE SNIP //-->
<PRE>
1.    ...
2.  Checkbox ap_cb = new Checkbox(&#147;Auto-pan&#148;,null,true);
3.  Checkbox order_cb = new Checkbox(&#147;-order&#148;,null,true);
4.  Checkbox i3_cb = new Checkbox(&#147;-i3&#148;);
5.  Checkbox r3_cb = new Checkbox(&#147;-r3&#148;,null,true);
6.  Checkbox x3_cb = new Checkbox(&#147;-x3&#148;,null,false);
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR>To use a <I>Checkbox</I> with a known state and no <I>Checkbox</I> group, you must place a <I>null</I>, as a placeholder, into the <I>group</I> parameter.<HR></FONT>
</BLOCKQUOTE>
<!-- CODE SNIP //-->
<PRE>
7.   Checkbox checkboxes[] = &#123;
8.        ap_cb,
9.        order_cb,
10.        i3_cb,
11.        r3_cb,
12.        x3_cb&#125;;
</PRE>
<!-- END CODE SNIP //-->
<P>To add the check boxes to a frame, we use a method called <I>addCheckBoxes</I>:</P>
<!-- CODE SNIP //-->
<PRE>
 public void addCheckBoxes( Checkbox checkboxes[]) &#123;
      for (int i=0; i &lt; checkboxes.length; i&#43;&#43;) &#123;
             add(checkboxes[i]);
             &#125;
 &#125;
</PRE>
<!-- END CODE SNIP //-->
<P>To perform computation with a <I>Checkbox</I>, you need only get its state. For example:</P>
<!-- CODE SNIP //-->
<PRE>
if (x3_cb.getState()) &#123;
         p.x_data[i] = p.x_data[i] * -1;
        &#125;
</PRE>
<!-- END CODE SNIP //-->
<P>It is possible to make the <I>Checkbox</I> event trigger computation. In some cases, this mode may be the preferred one; however, if computation will lag behind the user&#146;s input rate, feedback to the user will be required and the program may seem sluggish [Tog]. Because there are several check boxes, the approach taken by DiffCAD is to update the screen with a recomputation only during a <I>repaint</I>. This policy permits us to embed <I>Checkbox</I> states directly into equations.</P>
<H3><A NAME="Heading43"></A><FONT COLOR="#000077">The Scrollbar Class</FONT></H3>
<P>The <I>Scrollbar</I> class is a <I>Component</I> subclass. It is generally added to a <I>Container</I> class instance and is used to obtain a numeric quantity from the user. The <I>Scrollbar</I> excels at permitting a user to scroll data, such as an image or graph, in a window of limited size. The digital oscilloscope example (see Figure 3.8) has four scroll bars: top, bottom, left, and right. Their functions will be described in the &#147;Class Usage&#148; section. The box that slides along the scroll bar is typically called the <I>elevator</I>. Taking the elevator up is the same as clicking and holding on the box while dragging the pointing device&#146;s cursor to the top of the scroll bar.</P>
<H4 ALIGN="LEFT"><A NAME="Heading44"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
public class Scrollbar extends Component &#123;
public static final int     HORIZONTAL
public static final int     VERTICAL
public Scrollbar()
public Scrollbar(int orientation)
public Scrollbar(int orientation, int value, int visible, int minimum,
int maximum)
public synchronized void addNotify()
public int getOrientation()
public int getValue()
public void setValue(int value)
public int getMinimum()
public int getMaximum()
public int getVisible()
public void setLineIncrement(int l)
public int getLineIncrement()
public void setPageIncrement(int l)
public int getPageIncrement()
public void setValues(int value, int visible, int minimum, int maximum)
&#125;
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading45"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose that the following variables are predefined:
</P>
<!-- CODE SNIP //-->
<PRE>
int orientation;
int visible;
int minimum,  maximum;
int value;
</PRE>
<!-- END CODE SNIP //-->
<P>To construct a <I>Scrollbar</I> instance, you use this statement</P>
<!-- CODE SNIP //-->
<PRE>
Scrollbar sb;
</PRE>
<!-- END CODE SNIP //-->
<P>The constructor defaults to a vertical scroll bar:
</P>
<!-- CODE SNIP //-->
<PRE>
sb = new Scrollbar();
int orientation;
</PRE>
<!-- END CODE SNIP //-->
<P>The orientation is either <I>Scrollbar.HORIZONTAL</I> or <I>Scrollbar.VERTICAL</I>.</P>
<!-- CODE SNIP //-->
<PRE>
sb = new Scrollbar(orientation);
int value;
int pageSize, minimum, maximum;
</PRE>
<!-- END CODE SNIP //-->
<P>To make a <I>Scrollbar</I> instance with given orientation, value, visibility, minimum range and maximum range:</P>
<!-- CODE SNIP //-->
<PRE>
sb = new Scrollbar(orientation, value, visible, minimum, maximum);
</PRE>
<!-- END CODE SNIP //-->
<P>To make a peer for the <I>Scrollbar</I> instance:</P>
<!-- CODE SNIP //-->
<PRE>
sb.addNotify();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the orientation of the <I>Scrollbar</I>:</P>
<!-- CODE SNIP //-->
<PRE>
orientation = sb.getOrientation();
</PRE>
<!-- END CODE SNIP //-->
<P>To get and set the <I>value</I>:</P>
<!-- CODE SNIP //-->
<PRE>
value = sb.getValue();
sb.setValue(value);
</PRE>
<!-- END CODE SNIP //-->
<P><I>Value</I> is clipped to <I>Maximum</I> or <I>Minimum</I> if it is not between them.</P>
<P>To get the minimum and maximum of the <I>Scrollbar</I>:</P>
<!-- CODE SNIP //-->
<PRE>
value = sb.getMinimum();
value = sb.getMaximum();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the amount visible, in pixels:
</P>
<!-- CODE SNIP //-->
<PRE>
value = sb.getVisible();
</PRE>
<!-- END CODE SNIP //-->
<P>To set and get the elevator increment for an arrow click:
</P>
<!-- CODE SNIP //-->
<PRE>
sb.setLineIncrement(l);
l = sb.getLineIncrement);
</PRE>
<!-- END CODE SNIP //-->
<P>To set and get the elevator increment for a page click:
</P>
<!-- CODE SNIP //-->
<PRE>
sb.setPageIncrement(l);
l = sb.getPageIncrement();
</PRE>
<!-- END CODE SNIP //-->
<P>To set the values (<I>value</I> is clipped if it exceeds the valid range):</P>
<!-- CODE SNIP //-->
<PRE>
sb.setValues(value, visible, minimum, maximum);
&#125;
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="150-155.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="160-164.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 + -