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

📄 109-113.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=109-113//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch02/107-108.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="113-116.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 3<BR>The Graphical User Interface
</FONT></H2>
<P>This chapter provides an overview of Java&#146;s graphic user interface. Central to the look and feel of the Java GUI is the AWT (Abstract Window Toolkit). The AWT consists of a collection of classes, some of which are extended six or more levels deep. For example, a programmer who extends an <I>Applet</I> class inherits the methods and instance variables of <I>Object</I>, <I>Component</I>, <I>Container</I>, and <I>Panel</I> superclasses. For us to cover the <I>Applet</I> class would mean also describing the four base classes, something that is better left to references such as [Chan and Lee]. Our approach is to cover the material that is essential to understanding how to write digital signal processing programs. The AWT is rich with many GUI options and widgets, but we will cover only those that are essential to the task. The finer points of the AWT are better left to book dedicated to that subject, such as [Geary and McClellan].</P>
<P>We begin with the <I>Color</I> class and then turn to the <I>Graphics</I> class. For the purpose of digital signal processing we need to learn how to draw a line, a disk, a string, and an image and how to set colors and fonts. The <I>Graphics</I> class is deep, and we do not attempt to cover it completely.</P>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">The Color Class</FONT></H3>
<P>The <I>Color</I> class is a public final class that is based on the RGB color model. The class has several public final static colors that are predefined. You can specify an instance of the <I>Color</I> class using two variants of the additive color synthesis system: RGB (red, green, and blue) or HSB (hue, saturation, and brightness). The additive color synthesis system is based on the premise that black is the absence of color and white is the combination of all colors. For example, when red, green, and blue are combined in equal amounts, the resulting color is white. This system is consistent with electronic displays that emit light. The subtractive synthesis color system is based on the premise that black is the combination of all colors and white is the absence of color. This is a result of light absorbing pigments that are applied to a white background. The subtractive synthesis color primaries are CMY (cyan, magenta, and yellow). The AWT does not support subtractive synthesis.</P>
<H4 ALIGN="LEFT"><A NAME="Heading3"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
public final class Color &#123;
public final static Color white
public final static Color lightGray
public final static Color gray
public final static Color darkGray
public final static Color black
public final static Color red
public final static Color pink
public final static Color orange
public final static Color yellow
public final static Color green
public final static Color magenta
public final static Color cyan
public final static Color blue
public Color(int r, int g, int b)
public Color(int rgb)
public Color(float r, float g, float b)
public int getRed()
public int getGreen()
public int getBlue()
public int getRGB()
public Color brighter()
public Color darker()
public int hashCode()
public boolean equals(Object obj)
public String toString()
public static Color getColor(String nm)
public static Color getColor(String nm, Color v)
public static Color getColor(String nm, int v)
public static int HSBtoRGB(float hue, float saturation, float brightness)
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
public static Color getHSBColor(float h, float s, float b)
&#125;
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>Suppose that the following variables are defined:
</P>
<!-- CODE SNIP //-->
<PRE>
Color c,c1;
int r, g, b;
float rf, gf, bf;
int anInt;
</PRE>
<!-- END CODE SNIP //-->
<P>To access the built-in color names, we use the following:
</P>
<!-- CODE //-->
<PRE>
c = Color.white;
c = Color.gray;
c = Color.lightGray;
c = Color.darkGray;
c = Color.black;
c = Color.red;
c = Color.pink;
c = Color.orange;
c = Color.yellow;
c = Color.green;
c = Color.magneta;
c = Color.cyan;
c = Color.blue;
</PRE>
<!-- END CODE //-->
<P>To construct a new color, we use this:
</P>
<!-- CODE SNIP //-->
<PRE>
c = new Color(r, g, b);
</PRE>
<!-- END CODE SNIP //-->
<P>The AWT assumes that the <I>r</I>, <I>g</I>, and <I>b</I> quantities range from 0 to 255. If the range assumption is violated, the value is truncated. In fact, the color is typically a packed <I>int</I> consisting of a blue component in bits 0-7, a green component in bits 8-15, and a red component in bits 16-23. To instantiate a new color from an existing instance, we use this statement:</P>
<!-- CODE SNIP //-->
<PRE>
c1 = new Color(c);
</PRE>
<!-- END CODE SNIP //-->
<P>To instantiate a new color from red, green and blue components in the range from 0 to 1, inclusive, we use this:
</P>
<!-- CODE SNIP //-->
<PRE>
c = new Color(rf, gf, bf);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the components of a color, we use this:
</P>
<!-- CODE SNIP //-->
<PRE>
r = c.getRed();
r = c.getGreen();
r = c.getBlue();
</PRE>
<!-- END CODE SNIP //-->
<P>To get a 24-bit RGB color packed into an <I>int</I> and typed as an <I>int</I>, we use this:</P>
<!-- CODE SNIP //-->
<PRE>
anInt = c.getRGB();
</PRE>
<!-- END CODE SNIP //-->
<P>To brighten or darken a color:
</P>
<!-- CODE SNIP //-->
<PRE>
c.brighter();
c.darker();
</PRE>
<!-- END CODE SNIP //-->
<P>To obtain the color <I>hashCode</I> (implemented as <I>getRGB()</I>):</P>
<!-- CODE SNIP //-->
<PRE>
anInt = c.hashCode();
</PRE>
<!-- END CODE SNIP //-->
<P>To compare color values:
</P>
<!-- CODE SNIP //-->
<PRE>
aBoolean = c.equals(c2);
</PRE>
<!-- END CODE SNIP //-->
<P>To convert to a string:
</P>
<!-- CODE SNIP //-->
<PRE>
str = c.toString();
</PRE>
<!-- END CODE SNIP //-->
<P>If <I>nm</I> is a valid color property name, the <I>Integer</I> class can use the <I>getInteger</I> method to map the property name into a color. The following static methods are used:</P>
<!-- CODE SNIP //-->
<PRE>
c1 = Color.getColor(nm);
</PRE>
<!-- END CODE SNIP //-->
<P>To return a color if the property name is undefined:
</P>
<!-- CODE SNIP //-->
<PRE>
c1 = Color.getColor(nm, aColor);
</PRE>
<!-- END CODE SNIP //-->
<P>To return a color based on a 24-bit RGB color <I>int</I> if the name is undefined:</P>
<!-- CODE SNIP //-->
<PRE>
c1 = Color.getColor(nm, anInt);
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR>Color properties must be set by the Java application. They are not predefined.<HR></FONT>
</BLOCKQUOTE>
<P>To convert a floating-point description of hue, saturation, and brightness to the RGB model (with a 24-bit <I>int</I>) use the following:</P>
<!-- CODE SNIP //-->
<PRE>
// ranging from 0..1 inclusive
float hue, saturation, brightness;
anInt = Color.HSBtoRGB(hue, saturation, brightness);
</PRE>
<!-- END CODE SNIP //-->
<P>To convert from RBG to HSB, there are two methods to choose from:
</P>
<!-- CODE SNIP //-->
<PRE>
float hsbvals[];
int r, g, b; // r, g and b range from 0..255
hsbvals = Color.RGBtoHSB(r, g, b, null);
Color.RGBtoHSB(r, g, b, hsbvals);
</PRE>
<!-- END CODE SNIP //-->
<P>Both techniques return three values in the <I>hsbvals</I> array.</P>
<P>To make an instance of a color from an HSB floating-point triplet, use the following:</P>
<!-- CODE SNIP //-->
<PRE>
Color aColor = Color.HSBtoRGB(h, s, b);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch02/107-108.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="113-116.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 + -