﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-幻境</title><link>http://www.blogjava.net/jayliu/</link><description>We are extremely fortunate not to know precisely the kind of world we live in </description><language>zh-cn</language><lastBuildDate>Tue, 28 Apr 2026 19:03:17 GMT</lastBuildDate><pubDate>Tue, 28 Apr 2026 19:03:17 GMT</pubDate><ttl>60</ttl><item><title>提高工作效率之利器 --- 十大在线任务管理网站</title><link>http://www.blogjava.net/jayliu/archive/2010/08/05/328066.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 05 Aug 2010 13:42:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2010/08/05/328066.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/328066.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2010/08/05/328066.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/328066.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/328066.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 对于职场人士来说，每天都有如山如海的任务要执行。然而，要一一记住它们，仅凭聪明的脑筋显然是不够的。而目前的一些在线任务管理网站，为我们提供了一个将这些任务组织起来的一些方法。本文列出来一些比较好的在线任务管理系统，您可以尝试一下，让您的每日生活变得更有组织。&nbsp;&nbsp;<a href='http://www.blogjava.net/jayliu/archive/2010/08/05/328066.html'>阅读全文</a><img src ="http://www.blogjava.net/jayliu/aggbug/328066.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2010-08-05 21:42 <a href="http://www.blogjava.net/jayliu/archive/2010/08/05/328066.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CentOS5.3完美配置</title><link>http://www.blogjava.net/jayliu/archive/2009/05/01/268462.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Fri, 01 May 2009 01:40:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2009/05/01/268462.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/268462.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2009/05/01/268462.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/268462.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/268462.html</trackback:ping><description><![CDATA[
		<br />因为文章较长（一共六篇）就不一一贴出来了，请点击下面的链接查看详情：<br /><br /><a href="http://www.ondev.net/post/show/664" id="j_id47:5:j_id49" target="_blank">Centos 5.3服务器完美设置（一）</a><br /><p><a href="http://www.ondev.net/post/show/669" target="_blank">Centos 5.3服务器完美设置（二）</a></p><p><a href="http://www.ondev.net/post/show/685" target="_blank">Centos 5.3服务器完美设置（三）</a></p><p><a href="http://www.ondev.net/post/show/686" target="_blank">Centos 5.3服务器完美设置（四）</a></p><p><a href="http://www.ondev.net/post/show/699" target="_blank">Centos 5.3服务器完美设置（五）</a></p><p><a href="http://www.ondev.net/post/show/700" target="_blank">Centos 5.3服务器完美设置（六）</a></p><br /><br /><img src ="http://www.blogjava.net/jayliu/aggbug/268462.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2009-05-01 09:40 <a href="http://www.blogjava.net/jayliu/archive/2009/05/01/268462.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Collection框架：你可能不知道的一些小知识</title><link>http://www.blogjava.net/jayliu/archive/2009/04/08/264407.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Wed, 08 Apr 2009 02:28:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2009/04/08/264407.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/264407.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2009/04/08/264407.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/264407.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/264407.html</trackback:ping><description><![CDATA[
		<p>（原文发表于<a href="http://www.ondev.net/post/show/565">http://www.ondev.net/post/show/565</a>，转载请注明出处）<br /><br />关于Java Collection Framework，你可能已经知道如下一些事实 </p>
		<ol>
				<li>Vector是线程安全的，ArrayList不是 
</li>
				<li>ArrayList的读操作比LinkedList快，LinkedList的append操作比ArrayList快 
</li>
				<li>Set中不可能有两个相等的元素，也就是说，如果e1和e2都在同一个Set中，那么不可能有e1.equals(e2) 
</li>
				<li>HashMap是线程不安全的，HashTable是线程安全的 </li>
		</ol>
		<p>
				<br />但是你可能还不知道或者不了解这些事情：</p>
		<ol>
				<li>LinkedList不是线程安全的 
</li>
				<li>不管是在多线程还是单线程的环境下，ArrayList都要比Vector快很多倍 
</li>
				<li>Set中可以插入null，不过最多只会有一个 
</li>
				<li>HashMap中可以插入null，HashTable中不行 
</li>
				<li>TreeSet使用compareTo代替equals判断是否两个元素相等 
</li>
				<li>HashMap中的元素，无论是keySet还是valueSet，都不一定是按照插入时间先后排序的，HashSet也一样 
</li>
				<li>对于非线程安全的类，比如HashMap，ArrayList，TreeSet，可以使用Collections.synchronizedXXX方法（比如synchronizedSet，synchronizedList,synchronizedMap) 
</li>
				<li>你可以使用Collections.unmodifiableList来构建出一个不能被修改的List 
</li>
				<li>你可以使用Arrays.equals来判断两个数组是否相等 
</li>
				<li>WeakHashMap使用元素的引用而不是值作为key，也就是说必须在引用相同（a==b）的情况下才能找到相关的值 
</li>
				<li>对于WeakHashMap，一旦引用失效，相应的值也就不存在了，比如下面一段代码中： </li>
		</ol>
		<p>
		</p>
		<div class="bar">
				<div class="tools">
						<a onclick="dp.sh.Toolbar.Command('About',this);return false;" href="http://www.ondev.net/post/show/565#">
						</a> </div>
		</div>
		<div class="dp-highlighter">
				<ol class="dp-j">
						<li class="alt">
								<span>
										<span class="keyword">public</span>
										<span> </span>
										<span class="keyword">class</span>
										<span> TestHashMap {    </span>
								</span>
						</li>
						<li class="">
								<span>  </span>
						</li>
						<li class="alt">
								<span>    </span>
								<span class="keyword">public</span>
								<span> </span>
								<span class="keyword">static</span>
								<span> WeakHashMap wHmp= </span>
								<span class="keyword">new</span>
								<span> WeakHashMap();    </span>
						</li>
						<li class="">
								<span>       </span>
						</li>
						<li class="alt">
								<span>    </span>
								<span class="keyword">public</span>
								<span> </span>
								<span class="keyword">static</span>
								<span> </span>
								<span class="keyword">void</span>
								<span> main(String args[]){    </span>
						</li>
						<li class="">
								<span>       String s1 = </span>
								<span class="keyword">new</span>
								<span> String(</span>
								<span class="string">"one"</span>
								<span>);    </span>
						</li>
						<li class="alt">
								<span>       wHmp.put(s1,</span>
								<span class="keyword">new</span>
								<span> Integer(</span>
								<span class="number">
										<font color="#c00000">1</font>
								</span>
								<span>));    </span>
						</li>
						<li class="">
								<span>       addObject(wHmp);    </span>
						</li>
						<li class="alt">
								<span>       Set setHmp= wHmp.keySet();    </span>
						</li>
						<li class="">
								<span>           </span>
						</li>
						<li class="alt">
								<span>       </span>
								<span class="keyword">for</span>
								<span>(Iterator it=setHmp.iterator();it.hasNext();){    </span>
						</li>
						<li class="">
								<span>          System.out.println(wHmp.get(it.next()));    </span>
						</li>
						<li class="alt">
								<span>      }    </span>
						</li>
						<li class="">
								<span>           </span>
						</li>
						<li class="alt">
								<span>   }    </span>
						</li>
						<li class="">
								<span>       </span>
						</li>
						<li class="alt">
								<span>   </span>
								<span class="keyword">public</span>
								<span> </span>
								<span class="keyword">static</span>
								<span> </span>
								<span class="keyword">void</span>
								<span> addObject(WeakHashMap wHmp){    </span>
						</li>
						<li class="">
								<span>           </span>
						</li>
						<li class="alt">
								<span>     String s2 = </span>
								<span class="keyword">new</span>
								<span> String(</span>
								<span class="string">"two"</span>
								<span>);    </span>
						</li>
						<li class="">
								<span>     String s3 = </span>
								<span class="keyword">new</span>
								<span> String(</span>
								<span class="string">"three"</span>
								<span>);    </span>
						</li>
						<li class="alt">
								<span>     wHmp.put(s2,</span>
								<span class="keyword">new</span>
								<span> Integer(</span>
								<span class="number">
										<font color="#c00000">2</font>
								</span>
								<span>));    </span>
						</li>
						<li class="">
								<span>     wHmp.put(s3,</span>
								<span class="keyword">new</span>
								<span> Integer(</span>
								<span class="number">
										<font color="#c00000">3</font>
								</span>
								<span>));    </span>
						</li>
						<li class="alt">
								<span>     s2=</span>
								<span class="keyword">null</span>
								<span>;    </span>
						</li>
						<li class="">
								<span>     s3=</span>
								<span class="keyword">null</span>
								<span>;    </span>
						</li>
						<li class="alt">
								<span>     System.gc();    </span>
						</li>
						<li class="">
								<span>   }    </span>
						</li>
						<li class="alt">
								<span>}   </span>
						</li>
				</ol>
		</div>
		<span>
				<p>最后打印出来的结果只有"one”</p>
		</span>
<img src ="http://www.blogjava.net/jayliu/aggbug/264407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2009-04-08 10:28 <a href="http://www.blogjava.net/jayliu/archive/2009/04/08/264407.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Grails和Rome产生Rss</title><link>http://www.blogjava.net/jayliu/archive/2008/09/06/227394.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Sat, 06 Sep 2008 05:42:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2008/09/06/227394.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/227394.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2008/09/06/227394.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/227394.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/227394.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在grails中利用ROME产生RSS&nbsp;&nbsp;<a href='http://www.blogjava.net/jayliu/archive/2008/09/06/227394.html'>阅读全文</a><img src ="http://www.blogjava.net/jayliu/aggbug/227394.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2008-09-06 13:42 <a href="http://www.blogjava.net/jayliu/archive/2008/09/06/227394.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在tomcat中使用jconsole </title><link>http://www.blogjava.net/jayliu/archive/2008/08/15/222137.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Fri, 15 Aug 2008 00:50:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2008/08/15/222137.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/222137.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2008/08/15/222137.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/222137.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/222137.html</trackback:ping><description><![CDATA[
		<p>
				<br />
				<br />需要添加如下参数：</p>
		<p>-Dcom.sun.management.jmxremote</p>
		<p>-Dcom.sun.management.jmxremote.port=8086</p>
		<p>-Dcom.sun.management.jmxremote.authenticate=false</p>
		<p>-Dcom.sun.management.jmxremote.ssl=false</p>
		<p>启动JConsole以后会要求选择连接，切换到Remote标签页port填8086就可以了</p>
		<p> </p>
		<p>举例：</p>
		<p>catalina.bat中:</p>
		<p>set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8086 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false<br /><br />（本文也发表于<a href="http://www.ondev.net/story/show/49">http://www.ondev.net/story/show/49</a>，转载请注明出处）</p>
<img src ="http://www.blogjava.net/jayliu/aggbug/222137.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2008-08-15 08:50 <a href="http://www.blogjava.net/jayliu/archive/2008/08/15/222137.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT/Jface开发入门指南(十一) </title><link>http://www.blogjava.net/jayliu/archive/2005/11/06/18399.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Sun, 06 Nov 2005 05:09:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/11/06/18399.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/18399.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/11/06/18399.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/18399.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/18399.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><SPAN><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5">JFace中的工具条和菜单<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></SPAN></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">前一节中我们简单介绍了一下</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。其实所谓的</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就是一个最常用的事件，举个例子来说，对于一个按钮来说它可以有多个事件，比如按键，焦点，鼠标，等等等等吧，但是实际上在使用程序的时候，我们最关心的，就是按下去这个按钮会发生什么，这个其实就是所谓的</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。如果大家以前做过</SPAN><SPAN lang=EN-US>swing/awt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">变成的话，应该对</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不会陌生。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US>JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面，一个</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以对应多个</SPAN><SPAN lang=EN-US>GUI</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象，这些对象就是所谓的</SPAN><SPAN lang=EN-US>Contribution Item</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。比如我们在一般程序里面很常见的“文件”菜单，下面都会有“新建”，“保存”等等。同时我们可以在工具条上放置相应的按钮，那么这些都是有相同的功能，在</SPAN><SPAN lang=EN-US>JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面我们可以只写一个</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，然后把它映射到不同的</SPAN><SPAN lang=EN-US>ContributionItem</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">去，而不必为每个部件都写一串处理事件。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们下面还是通过一个简单的例子来说明，在</SPAN><SPAN lang=EN-US>JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中怎么使用菜单和工具条这两种最基本也是最有用的</SPAN><SPAN lang=EN-US>Contribution Item</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们这个程序写得很傻，就是一个光秃秃的窗口上做了一个菜单和工具条按钮，功能也只有一个，就是每次点一下，就弹出一个输入框来问你名字是什么，然后显示一个</SPAN><SPAN lang=EN-US>Hello, xxx</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之类的。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先我们还是来写一个</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类：<BR><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;SayHiAction&nbsp;</SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000">&nbsp;Action&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;Shell&nbsp;shell;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;SayHiAction(Shell&nbsp;shell)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">super</SPAN><SPAN style="COLOR: #000000">();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.shell&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;shell;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.setText(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Say&amp;Hi@Ctrl+H</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;@Override<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;run()&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputDialog&nbsp;input&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;InputDialog(shell,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Input&nbsp;your&nbsp;name</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Please&nbsp;input&nbsp;your&nbsp;name&nbsp;here:</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(input.open()&nbsp;</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">&nbsp;Window.OK)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageDialog.openInformation(shell,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Hello</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Hello,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">17</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;input.getValue()&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">20</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">22</SPAN>&nbsp;<SPAN style="COLOR: #000000">}<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN></DIV>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt" align=center><BR><BR></SPAN></FONT><EM><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码段</SPAN> <SPAN lang=EN-US><SPAN style="mso-no-proof: yes">17</SPAN></SPAN></FONT></EM></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这只是一个很简单的</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类，没有太多可说的。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">然后我们创建一个</SPAN><SPAN lang=EN-US>ApplicationWindow</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类：<BR><BR></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;Hiyou&nbsp;</SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000">&nbsp;ApplicationWindow&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;SayHiAction&nbsp;hiaction;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;Hiyou(Shell&nbsp;parentShell)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">super</SPAN><SPAN style="COLOR: #000000">(parentShell);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hiaction</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;SayHiAction(getShell());<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addMenuBar();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addToolBar(SWT.FLAT&nbsp;</SPAN><SPAN style="COLOR: #000000">|</SPAN><SPAN style="COLOR: #000000">&nbsp;SWT.WRAP);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">12</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;@Override<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000">&nbsp;ToolBarManager&nbsp;createToolBarManager(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;style)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ToolBarManager&nbsp;toolbar</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ToolBarManager();<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toolbar.add(hiaction);<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;toolbar;<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">19</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;@Override<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000">&nbsp;MenuManager&nbsp;createMenuManager()&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MenuManager&nbsp;menubar</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MenuManager();<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MenuManager&nbsp;fileMenu</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;MenuManager(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&amp;File</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileMenu.add(hiaction);<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menubar.add(fileMenu);<BR></SPAN><SPAN style="COLOR: #008080">25</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;menubar;<BR></SPAN><SPAN style="COLOR: #008080">26</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">27</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">28</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">29</SPAN>&nbsp;<SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">&nbsp;args<BR></SPAN><SPAN style="COLOR: #008080">30</SPAN>&nbsp;<SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">31</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">32</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hiyou&nbsp;window</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Hiyou(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">33</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.setBlockOnOpen(</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">34</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.open();<BR></SPAN><SPAN style="COLOR: #008080">35</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Display.getCurrent().dispose();<BR></SPAN><SPAN style="COLOR: #008080">36</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">37</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">38</SPAN>&nbsp;<SPAN style="COLOR: #000000">}<BR></SPAN><SPAN style="COLOR: #008080">39</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN></DIV>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt">&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoCaption style="MARGIN: 3pt 0cm 11pt 90pt; TEXT-ALIGN: center" align=center><EM><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码段</SPAN> <SPAN lang=EN-US><SPAN style="mso-no-proof: yes">18</SPAN></SPAN></FONT></EM></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">大家可能已经注意到了，在这里面我们重载了</SPAN><SPAN lang=EN-US>createMenuManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">createToolBarManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">两个方法，它们的用途就和名字一样，一个是用来创建菜单的，一个是用来创建工具条的。重载了这两个方法以后，通过在构造函数中调用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">addMenuBar</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">addToolBar</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">让工具条和菜单显示出来。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">这里值得一提的是</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">MenuManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">ToolBarManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">类，如果大家翻一下</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">API</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">文档的话会发现它们都是所谓的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">contribution manager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">（实现了</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">IConntributionManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">接口），你可以通过这些</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">contribution manager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">来实现对特定组件的管理（添加删除等等）。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">具体到菜单的创建，看了我们上面的代码就很明白了，就直接调用相应</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">MenuManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">add</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">方法把</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加上就可以了。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">会自动找到这个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">getText</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">方法设置菜单的文字。如果是有好几层菜单，那么只要在重新</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">new</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">MenuManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">添加到已有的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">MenuManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">里面就可以了。就象前面代码中的：<BR><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">menubar.add(fileMenu);</SPAN></DIV>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><BR><BR></SPAN></FONT><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">至于工具条就更简单了，创建一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">ToolBarManager</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">然后直接</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">add</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">对应的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">就可以了。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><FONT size=3><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">添加图标</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia"><o:p></o:p></SPAN></FONT></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果菜单只是文字还没有什么，如果你的工具条都是文字是不是会显得干巴巴的？其实只要我们为</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置</SPAN><SPAN lang=EN-US>ImageDescriptor</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">就可以了，比如你可以自己画一个图标保存到</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的包下面（我画了一个</SPAN><SPAN lang=EN-US>hi.gif</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">），然后把</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的构造函数改写成这样：<BR><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;SayHiAction(Shell&nbsp;shell)&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">super</SPAN><SPAN style="COLOR: #000000">();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.shell&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;shell;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.setText(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Say&amp;Hi@Ctrl+H</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.setImageDescriptor(ImageDescriptor.createFromFile(</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.getClass(),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">hi.gif</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));<BR>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></DIV>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><BR><BR></SPAN></FONT><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">大家注意最后一句话，就是为</SPAN><SPAN lang=EN-US>action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置图标的。然后再运行一下就会发现菜单和工具栏都有图标了。</SPAN></FONT></P>
<H1 style="MARGIN: 11pt 0cm"><SPAN><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5">结束语<o:p></o:p></FONT></FONT></SPAN></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这一系列的文章陆陆续续写到今天，也就写完了。回头看一下，虽然内容都很浅显，不过我觉得在</SPAN><SPAN lang=EN-US>swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US>JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中文资料缺乏的今天，可能也可以给大家带来一些启迪。今后我还会写一些</SPAN><SPAN lang=EN-US>eclipse</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">平台开发的文章，大家可以登陆到我的</SPAN><SPAN lang=EN-US>blog</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">（</SPAN><SPAN lang=EN-US><A href="http://blog.csdn.net/jayliu">http://blog.csdn.net/jayliu</A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）查看。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">另外大家也可以登陆到在中国</SPAN><SPAN lang=EN-US>Eclipse</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">社区（</SPAN><SPAN lang=EN-US><A href="http://www.eclipseworld.org/">http://www.eclipseworld.org</A></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">），在那里你也可以找到很多的帮助和支持，当然，你也可以在那里找到我。</SPAN></FONT><SPAN lang=EN-US><o:p></o:p></SPAN></P><img src ="http://www.blogjava.net/jayliu/aggbug/18399.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-11-06 13:09 <a href="http://www.blogjava.net/jayliu/archive/2005/11/06/18399.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT/Jface开发入门指南(十)</title><link>http://www.blogjava.net/jayliu/archive/2005/10/14/15537.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Fri, 14 Oct 2005 09:42:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/10/14/15537.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/15537.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/10/14/15537.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/15537.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/15537.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><SPAN><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5">JFace中的事件模式<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></SPAN></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">大家好，因为工作的事情搞了一个多月，现在终于暂时安定下来了。这一系列的文章我也会继续往下写。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">在这一节中，我会向大家介绍</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">中的事件模式。其实我相信这篇文章的读者应该大部分都会接触</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">eclipse</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">，这样可能也会接触过</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">eclipse</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的插件开发。就是没有接触过，大家也可能会有在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">eclipse</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">里面新建工程的时候出于各种原因（比如好奇心）点了</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">plug-in project</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的时候吧。其实作为一个程序员来讲，保持好奇是很重要的。如果你大概看过一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">plug-in project</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的结构，虽然可能不能全部理解，但是我相信也应该对</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">之类有一些了解。我们这一节主要就是围绕</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">来写的。为了增加可读性，我们首先介绍几个名词，这些名词都可以从</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">eclipse</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的文档中找到。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia"><o:p></o:p></SPAN></FONT></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><FONT size=3><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">什么是</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Action<o:p></o:p></SPAN></FONT></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: Georgia">JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">中的一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">可以简单地理解成一个<SPAN style="COLOR: blue">命令</SPAN>。那么它和<SPAN style="COLOR: blue">事件</SPAN>有什么关系呢？比如说我点了一个菜单，那么点击本身就是一个事件，但是这个事件的影响就是相应的命令被执行了。大家日常使用的一些软件比如</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Office</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">都是有菜单和工具栏的，而一个菜单项和一个工具栏可能执行的是同一个命令。比如</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Word</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">里面要新建一个文档的话可以通过</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">“</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">文件</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">”</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">菜单下的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">“</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">新建</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">”</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">实现，也可以通过点击工具栏上相应的图标实现。这个新建地功能本身在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">里面是可以使用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">来实现的。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">里面，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">可以关联到菜单，工具条，以及按钮（也就是</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia">Button</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">）。当然关于如何关联，我们会在后面向大家详细介绍。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Georgia"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US>JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面的定义是一个接口</SPAN><SPAN lang=EN-US>org.eclipse.jface.action.IAction</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。当然实际上你写程序的时候必须自己来实现这个接口，写出自己的</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类来。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN lang=EN-US>IAction</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面最重要的方法是</SPAN><SPAN lang=EN-US>run()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，它也是事件触发以后执行的代码。其他的方法都是一些辅助性的方法，不是我们要关注的重点。为了能够将精力集中在我们所关注的事情上，通常我们不是实现</SPAN><SPAN lang=EN-US>IAction</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口，而是通过继承</SPAN><SPAN lang=EN-US>org.eclipse.jface.action.Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个抽象类来实现</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。下面我们通过一个例子来说明</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的用法。<BR></SPAN></FONT><SPAN lang=EN-US><o:p></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: Georgia"><FONT size=3>Hello,Action!<o:p></o:p></FONT></SPAN></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先我们先不管用户界面，先定义一个最简单的</SPAN><SPAN lang=EN-US>Action</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">类。<BR><BR></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloAction&nbsp;</SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000">&nbsp;Action{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;Shell&nbsp;shell;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloAction(Shell&nbsp;shell)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">super</SPAN><SPAN style="COLOR: #000000">(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&amp;Hello</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,Action.AS_PUSH_BUTTON);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.shell</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">shell;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;@Override<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;run()&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageDialog.openInformation(shell,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Hello</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Hello,Action!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN>&nbsp;<SPAN style="COLOR: #000000">}<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN></DIV>
<P class=MsoCaption style="MARGIN: 3pt 0cm 11pt 90pt; TEXT-ALIGN: center" align=center><EM><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><BR>代码段</SPAN><FONT face="Times New Roman"> <SPAN lang=EN-US><SPAN style="mso-no-proof: yes">1</SPAN></SPAN><SPAN lang=EN-US>5<o:p></o:p></SPAN></FONT></EM></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这段代码其实应该还是很好读懂的。带参的构造函数带进来一个</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Shell</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实例，而</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">run()</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方法说明了这个</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Action</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的功能就是显示一个对话框。第</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">5</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行中的代码调用了父类的构造函数，其中第一个参数是</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Action</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对应的文本，前面的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">&amp;</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">符号表明了</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">H</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是热键，而第二个参数则是一个风格参数。如果大家继续向后看的话，就会发现这个</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Action</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">被附加在了一个按钮上面，而按钮上显示的文本就是</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Hello</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，如果你定义的风格不是</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">AS_PUSH_BUTTON</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">而是</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">AS_RADIO_BUTTON</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的话就会发现按钮已经不是一个纯粹的按钮了，而是一个单选钮。相应的其他风格可以参照</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Javadoc。<BR></FONT></SPAN></P>
<P align=left></P>
<P align=left></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloJface&nbsp;</SPAN><SPAN style="COLOR: #0000ff">extends</SPAN><SPAN style="COLOR: #000000">&nbsp;ApplicationWindow&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloJface(Shell&nbsp;shell)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">super</SPAN><SPAN style="COLOR: #000000">(shell);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000">&nbsp;Control&nbsp;createContents(Composite&nbsp;parent)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloAction&nbsp;action</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloAction(parent.getShell());<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ActionContributionItem&nbsp;aci</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ActionContributionItem(action);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aci.fill(parent);<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;parent;<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">/**</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</SPAN><SPAN style="COLOR: #808080">@param</SPAN><SPAN style="COLOR: #008000">&nbsp;args<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN>&nbsp;<SPAN style="COLOR: #008000">&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">18</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloJface&nbsp;demo&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloJface(</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demo.setBlockOnOpen(</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;demo.open();<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Display.getCurrent().dispose();<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN>&nbsp;<SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">23</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;}<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN>&nbsp;<SPAN style="COLOR: #000000">}</SPAN></DIV>
<P class=MsoCaption style="MARGIN: 3pt 0cm 11pt 90pt; TEXT-ALIGN: center" align=center><EM><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><BR>代码段</SPAN><SPAN lang=EN-US><FONT face="Times New Roman"> 16</FONT></SPAN></EM></P>
<P align=left><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-language: HE; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">和前面一节的代码相比，我们只是修改了</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-fareast-font-family: 宋体; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">createContents</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">方法。首先创建了一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-fareast-font-family: 宋体; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">HelloAction</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">的实例，然后又创建了一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-fareast-font-family: 宋体; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">ActionContributionItem</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">的实例，最后调用了这个实例的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-fareast-font-family: 宋体; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">fill</SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">方法将按钮添加到窗口中，这就是全部了。是不是很简单呢？程序运行出来的效果如下图：</SPAN><BR></P>
<P align=center><IMG height=234 alt=r_helloaction.JPG src="http://www.blogjava.net/images/blogjava_net/jayliu/1354/r_helloaction.JPG" width=517 border=0><BR><BR></P>
<P class=MsoCaption style="MARGIN: 3pt 0cm 11pt 90pt; TEXT-ALIGN: center" align=center><EM><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><FONT face="Times New Roman"> <SPAN lang=EN-US><SPAN style="mso-no-proof: yes">1</SPAN></SPAN><SPAN lang=EN-US>6</SPAN></FONT></EM></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可能看了这个例子，你会认为</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">ActionContributionItem</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这个类表示的就是一个按钮了。但是实际上并不是的，它在图形界面上表示成什么样子，随着不同的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">fill</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">调用又有不同。在下一节中，我会向大家深入介绍</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">Contribution Item</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以及</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">JFace</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的菜单，工具条等的应用。这一节就到这里结束了，因为刚刚换了工作环境，有很多事情需要去做，所以写得比较短，请大家见谅：）。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></P>
<P align=center>&nbsp;</P></SPAN></FONT></o:p></SPAN><img src ="http://www.blogjava.net/jayliu/aggbug/15537.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-10-14 17:42 <a href="http://www.blogjava.net/jayliu/archive/2005/10/14/15537.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在WebLogic中使用Hibernate</title><link>http://www.blogjava.net/jayliu/archive/2005/07/11/7516.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Mon, 11 Jul 2005 11:17:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/07/11/7516.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/7516.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/07/11/7516.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/7516.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/7516.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;关于这个话题，javaeye其实有一篇文章专门介绍了（http://www.javaeye.com/viewtopic.php?t=245），但是可能不是很详细，最近也有一些人我这方面的问题，所以在这里重新介绍一下。不过我还是推荐你在看本文之前首先看一下上面提到的那篇文章。首先说明一下我们这里使用的程序，为了更容易理解，我们使用hibernate文档（英文版： http://w...&nbsp;&nbsp;<a href='http://www.blogjava.net/jayliu/archive/2005/07/11/7516.html'>阅读全文</a><img src ="http://www.blogjava.net/jayliu/aggbug/7516.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-07-11 19:17 <a href="http://www.blogjava.net/jayliu/archive/2005/07/11/7516.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2SE5.0新特性---变长参数(Varargs)</title><link>http://www.blogjava.net/jayliu/archive/2005/05/22/5055.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Sun, 22 May 2005 08:46:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/22/5055.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/5055.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/22/5055.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/5055.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/5055.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">变长参数（</SPAN><SPAN lang=EN-US><FONT face=Arial>Varargs</FONT></SPAN><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">）</SPAN></FONT></FONT></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">与泛型一样，变长参数是</SPAN><SPAN lang=EN-US>C++</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中有而</SPAN><SPAN lang=EN-US>Java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中没有的一种语言特性，在过去如果我们想向一个函数传递可变数量的函数，就必须首先将这些参数放入一个数组中，然后将数组传递给函数。就如同下面所作的一样：</SPAN></FONT></P>
<P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2>Object[] arguments = { 640, "kb", "anybody", "Bill Gates" };<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2>String result = MessageFormat.format(<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>"{3}:{0,number,integer}{1} ought to be enough for {2}<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>",<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>arguments);<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在</SPAN><SPAN lang=EN-US>J2SE5.0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中，参数仍然是被放入一个数组中传给对应的方法，但是不同的是，你不再需要手动的创建数组，而是只需要将那些参数罗列出来，其他的工作由虚拟机替你完成。所以现在我们可以这样写：</SPAN></FONT></P>
<P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2>String result = MessageFormat.format(<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>"{3}:{0,number,integer}{1} ought to be enough for {2}<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>",<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>640, "kb", "anybody", "Bill Gates");<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>我们通过一个示例函数来说明使用变长参数函数的定义。这个函数打印出一个人养的几条狗的名字。</FONT></SPAN></P>
<P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2>private void printDogNames(String... dogs)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.out.println("I have " + dogs.length + " dogs:");<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>for(String dogname:dogs)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.out.println(dogname);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">事实上变长参数</SPAN><SPAN lang=EN-US>dogs</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是一个数组。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一个函数的参数中只能有一个变长参数，所以类似下面的定义是<SPAN style="COLOR: red">不合法</SPAN>的：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 480; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; mso-bidi-font-family: 'Courier New'"><FONT size=2>private void printDogNames(String... dogs,float... dogage)<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果决定把函数参数设置为可变长度的，你必须想到这样一种情况，就是调用的程序很可能会不给你传任何的参数，这个时候作为参数的数组</SPAN><SPAN lang=EN-US>length</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为</SPAN><SPAN lang=EN-US>0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，而这在语法上是完全合法的，所以你必须在函数定义中考虑到这种情况。</SPAN></FONT></P>
<P>&nbsp;</P><img src ="http://www.blogjava.net/jayliu/aggbug/5055.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-22 16:46 <a href="http://www.blogjava.net/jayliu/archive/2005/05/22/5055.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT/Jface开发入门指南（三） </title><link>http://www.blogjava.net/jayliu/archive/2005/05/19/4875.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 19 May 2005 09:33:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/19/4875.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4875.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/19/4875.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4875.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4875.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 初步体验widget 大家好，五一已经过去了，你们玩得开心么？在前面的两篇文章中，我向大家介绍了swt的一些基本知识，现在让我们继续下去讨论一下swt中的widget相关的一些知识以及介绍几种最为简单的widget。从Widget和Control开始Widget是Control的父类，而Control是我们使用的大多数部件的父类。我们在以前的一些编程语言中可能接触过“控件”或者“组...&nbsp;&nbsp;<a href='http://www.blogjava.net/jayliu/archive/2005/05/19/4875.html'>阅读全文</a><img src ="http://www.blogjava.net/jayliu/aggbug/4875.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-19 17:33 <a href="http://www.blogjava.net/jayliu/archive/2005/05/19/4875.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT/Jface开发入门指南（二）</title><link>http://www.blogjava.net/jayliu/archive/2005/05/18/4460.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Wed, 18 May 2005 02:35:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/18/4460.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4460.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/18/4460.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4460.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4460.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-language: AR-SA">从</SPAN><SPAN lang=EN-US style="mso-bidi-font-family: Arial; mso-bidi-language: AR-SA"><FONT face=Arial>Hello, world!</FONT></SPAN><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-language: AR-SA">开始了解</SPAN><SPAN lang=EN-US style="mso-bidi-font-family: Arial; mso-bidi-language: AR-SA"><FONT face=Arial>Display</FONT></SPAN><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-language: AR-SA">和</SPAN><SPAN lang=EN-US style="mso-bidi-font-family: Arial; mso-bidi-language: AR-SA"><FONT face=Arial>Shell<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></FONT></FONT></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">在这一节中，我们从前面所列举出来的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Hello, world!</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">程序开始对</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">进行一些初步的探索。所谓的初步是指，我们会介绍编写</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">程序的基本思路，以及对两个重要的类</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">:Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">作一些介绍。<BR></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">因为这一节和前一节是分成两个部分贴出来的，所以我仍然将</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Hello, world!</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">的代码段在下面列出来：</SPAN></FONT><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><BR></P>
<DIV align=center>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV align=left><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package&nbsp;swtjfacesample;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;org.eclipse.swt.SWT;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;org.eclipse.swt.widgets.Display;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;org.eclipse.swt.widgets.Shell;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import&nbsp;org.eclipse.swt.widgets.Text;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_191_748_Open_Image onclick="this.style.display='none'; Codehighlighter1_191_748_Open_Text.style.display='none'; Codehighlighter1_191_748_Closed_Image.style.display='inline'; Codehighlighter1_191_748_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_191_748_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_191_748_Closed_Text.style.display='none'; Codehighlighter1_191_748_Open_Image.style.display='inline'; Codehighlighter1_191_748_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloSwt&nbsp;</SPAN><SPAN id=Codehighlighter1_191_748_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_191_748_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_197_254_Open_Image onclick="this.style.display='none'; Codehighlighter1_197_254_Open_Text.style.display='none'; Codehighlighter1_197_254_Closed_Image.style.display='inline'; Codehighlighter1_197_254_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_197_254_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_197_254_Closed_Text.style.display='none'; Codehighlighter1_197_254_Open_Image.style.display='inline'; Codehighlighter1_197_254_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_197_254_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_197_254_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">*<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Hello,world!<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;args<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_302_746_Open_Image onclick="this.style.display='none'; Codehighlighter1_302_746_Open_Text.style.display='none'; Codehighlighter1_302_746_Closed_Image.style.display='inline'; Codehighlighter1_302_746_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_302_746_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_302_746_Closed_Text.style.display='none'; Codehighlighter1_302_746_Open_Image.style.display='inline'; Codehighlighter1_302_746_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</SPAN><SPAN id=Codehighlighter1_302_746_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_302_746_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Display&nbsp;display&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Display();<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Shell&nbsp;shell&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Shell(display);<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Text&nbsp;helloText&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Text(shell,&nbsp;SWT.CENTER);<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloText.setText(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Hello,World!</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;helloText.pack();<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell.pack();<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell.open();<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">25</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_609_712_Open_Image onclick="this.style.display='none'; Codehighlighter1_609_712_Open_Text.style.display='none'; Codehighlighter1_609_712_Closed_Image.style.display='inline'; Codehighlighter1_609_712_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_609_712_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_609_712_Closed_Text.style.display='none'; Codehighlighter1_609_712_Open_Image.style.display='inline'; Codehighlighter1_609_712_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">shell.isDisposed())&nbsp;</SPAN><SPAN id=Codehighlighter1_609_712_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_609_712_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">26</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_655_702_Open_Image onclick="this.style.display='none'; Codehighlighter1_655_702_Open_Text.style.display='none'; Codehighlighter1_655_702_Closed_Image.style.display='inline'; Codehighlighter1_655_702_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_655_702_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_655_702_Closed_Text.style.display='none'; Codehighlighter1_655_702_Open_Image.style.display='inline'; Codehighlighter1_655_702_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #000000">!</SPAN><SPAN style="COLOR: #000000">display.readAndDispatch())&nbsp;</SPAN><SPAN id=Codehighlighter1_655_702_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_655_702_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">27</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.sleep();<BR></SPAN><SPAN style="COLOR: #008080">28</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">29</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">30</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.dispose();<BR></SPAN><SPAN style="COLOR: #008080">31</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">32</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">33</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV></DIV>
<P class=MsoCaption style="MARGIN: 3pt 0cm 11pt 90pt; TEXT-ALIGN: center" align=center><BR><EM>代码段</EM></SPAN><EM> <SPAN lang=EN-US><SPAN style="mso-no-proof: yes">2</SPAN></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></EM></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">这段程序虽然很简单，但是它反映了我们书写</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">程序的步骤，这些步骤是：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><SPAN style="mso-list: Ignore"><FONT size=2>1.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">创建一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><SPAN style="mso-list: Ignore"><FONT size=2>2.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">创建一个或者多个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象，你可以认为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">代表了程序的窗口。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><SPAN style="mso-list: Ignore"><FONT size=2>3.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">内创建各种部件（</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">widget</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">）</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><SPAN style="mso-list: Ignore"><FONT size=2>4.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对各个部件进行初始化（外观，状态等），同时为各种部件的事件创建监听器（</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">listener</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">）</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><SPAN style="mso-list: Ignore"><FONT size=2>5.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">调用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">open()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">方法以显示窗体</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><SPAN style="mso-list: Ignore"><FONT size=2>6.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">各种事件进行监听并处理，直到程序发出退出消息</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Courier New'"><SPAN style="mso-list: Ignore"><FONT size=2>7.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">调用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">dispose()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">方法以结束程序。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Hello,world!</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">程序中，为了让程序更加简单，我们没有创建事件监听器，在以后的内容中会进行专门介绍。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">现在让我们稍微深入一些，看一下这些</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display,Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">有什么作用以至于我们每个程序都必须有它们存在。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><FONT size=3><SPAN lang=EN-US style="mso-bidi-font-family: Arial; mso-bidi-language: AR-SA"><FONT face=Arial>Display:</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-bidi-language: AR-SA">与操作系统沟通的桥梁</SPAN><SPAN lang=EN-US style="mso-bidi-font-family: Arial; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">我们在前面说过，每个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">程序在最开始都必须创建一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">对象。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">对象起什么作用呢？它是</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">与操作系统沟通的一座桥梁。它负责</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">和操作系统之间的通信。它将</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt/JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">的各种调用转化为系统的底层调用，控制操作系统为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">分配的资源。同时我们也可以通过</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">对象得到操作系统的一些信息。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">是一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">“</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">幕后工作者</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">”</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">，它为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt/JFace</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">提供支持，但是你并不能够从某个用户界面中看到它的影子。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">在前面的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Hello,world!</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">程序中，我们可以看到构建一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">对象是和普通的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">对象一样通过构造函数实现的。它为实现图形界面准备了最基本的条件。而在程序结束时我们必须显式地调用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">dispose() </SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">方法来释放程序运行中所获得的资源。一般来说，一个程序只需要一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">对象，当然没有人禁止你创建多个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">对象。但是在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA">javadoc</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA">中，我们可以看到关于这个问题一些描述：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><FONT size=2>“Applications which are built with SWT will <I>almost always</I> require only a single display. In particular, some platforms which SWT supports will not allow more than one <I>active</I> display. In other words, some platforms do not support creating a new display if one already exists that has not been sent the </FONT></SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.0pt">dispose()</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><FONT size=2> message.”<o:p></o:p></FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">有着众多的方法，我们不可能一一介绍。在这里只挑选几个可能会比较常用的作一些简单介绍。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-family: Wingdings; mso-fareast-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>l</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">setData()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">getData()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">：这一对函数允许我们为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象设定一些数据，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">setData()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的参数中</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">key</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">value</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">类似于我们在使用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Map</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象中</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">key</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">value</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的含义。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-family: Wingdings; mso-fareast-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>l</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">getShells()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">得到关联到该</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象的所有没有</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">dispose</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-family: Wingdings; mso-fareast-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>l</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">getCurrent()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">得到与用户交互的当前线程</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-family: Wingdings; mso-fareast-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>l</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">readAndDispatch()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">得到事件并且调用对应的监听器进行处理</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-family: Wingdings; mso-fareast-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>l</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">sleep()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">等待事件发生</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><FONT size=3><SPAN lang=EN-US style="mso-bidi-font-family: Arial"><FONT face=Arial>Shell:</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">窗口</SPAN><SPAN lang=EN-US style="mso-bidi-font-family: Arial"><o:p></o:p></SPAN></FONT></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象就是一个窗口。你可以在上面放置各种部件创建丰富的图形界面。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">我们都知道窗口有很多种，比如窗口有可以调整大小的，有不可以的，有的没有最大化最小化按钮。这些窗体的特征在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中被成为风格（</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">style</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">）。一个窗体的风格可以用一个整数进行定义。这些风格的定义在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">org.eclipse.swt.SWT</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象可用的风格包括：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE , PLICATION_MODAL, MODELESS, PRIMARY_MODAL,</SPAN><?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">S YSTEM_MODAL</SPAN></st1:place><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">这些风格我们不作一一介绍，你可以从他们字面意义看出一些含义来，当然也可以参考对应的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">javadoc</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">我们可以在一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的构造函数中定义它的风格，比如在前面的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Hello,world!</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">程序中，我们可以这样定义</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><o:p>&nbsp;</P>
<DIV align=center>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV align=left><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">Shell&nbsp;shell&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Shell(display,SWT.CLOSE&nbsp;</SPAN><SPAN style="COLOR: #000000">|</SPAN><SPAN style="COLOR: #000000">&nbsp;SWT.SYSTEM_MODAL);</SPAN></DIV></DIV></DIV>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"></o:p></FONT></SPAN>&nbsp;</P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">最后得到的窗体没有最大化和最小化按钮，并且大小是固定不变的。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">因为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">运行于各种平台之上，而这些平台上的窗口管理器千差万别，所以所有这些风格都不是肯定可以实现的。在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">javadoc</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中，这被称为暗示（</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">hints</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">）。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象的方法大都和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">GUI</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">有关，比如</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">setEnabled()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">设定了窗体是否能够和用户进行交互，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">setVisble()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">设定了窗体是否可见，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">setActive()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">将窗体设为当前的活动窗口。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">我们可以用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">open()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">方法打开一个窗体，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">close()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">方法关闭一个窗体。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><FONT size=3><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">小结</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">本节讨论了</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Display</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Shell</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的一些概念，这是我们以后进一步了解</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">swt</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的基础。在下一节中，我将介绍各种部件（</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">widget</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">）的用法，所谓部件，是指文本框，标签等</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">UI</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">实体。</SPAN></FONT><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P><img src ="http://www.blogjava.net/jayliu/aggbug/4460.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-18 10:35 <a href="http://www.blogjava.net/jayliu/archive/2005/05/18/4460.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT/Jface开发入门指南（一）</title><link>http://www.blogjava.net/jayliu/archive/2005/05/17/4389.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Tue, 17 May 2005 00:45:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/17/4389.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4389.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/17/4389.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4389.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4389.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: SWT/Jface开发入门指南写在前面的话终于决定提起笔来写一篇关于swt和JFace编程的文章。在开始之前，我想先介绍一下你能够从将要出现的这一系列文章里得到什么，以及更重要的，你不能得到什么。我们的时间是如此之重要，以至于我们很难容忍把它浪费在自己不关心的事情上。因为我刚开始写，所以到底这些文章会分成几次发布出来，也很难讲。但是我心里大体有这样一个提纲。也就是说，我打算介绍以下方面...&nbsp;&nbsp;<a href='http://www.blogjava.net/jayliu/archive/2005/05/17/4389.html'>阅读全文</a><img src ="http://www.blogjava.net/jayliu/aggbug/4389.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-17 08:45 <a href="http://www.blogjava.net/jayliu/archive/2005/05/17/4389.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>准时的blog.csdn.net</title><link>http://www.blogjava.net/jayliu/archive/2005/05/16/4326.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Mon, 16 May 2005 01:15:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/16/4326.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4326.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/16/4326.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4326.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4326.html</trackback:ping><description><![CDATA[经过几天的观察，得出一个结论，csdn blog基本上是每天九点开始崩溃，到晚上接近六点的时候恢复正常。<img src ="http://www.blogjava.net/jayliu/aggbug/4326.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-16 09:15 <a href="http://www.blogjava.net/jayliu/archive/2005/05/16/4326.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>透视迭代开发</title><link>http://www.blogjava.net/jayliu/archive/2005/05/14/4283.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Sat, 14 May 2005 02:08:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/14/4283.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4283.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/14/4283.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4283.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4283.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">引子：我们为什么需要迭代开发？</SPAN><SPAN lang=EN-US style="mso-fareast-font-family: 宋体"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></FONT></FONT></H1>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>我们都知道，人对于世界的认识是一项主观活动，它受到各种因素的影响，使得我们不能够一下子对所要认知的事物有一个清晰的了解。具体到软件开发中来，我们会发现，你很难在开发之前弄清楚客户所有的需求。一方面，客户对自己想要什么可能并没有一个明确的想法，这就好比在买衣服的时候，我们在专卖店里看到一个衣服，会觉得自己穿起来很帅，但是你仍然需要把它真实的穿在身上才能看到实际效果，而在你看到这件衣服之前，你能够仅仅凭着想象在脑海里刻画出这件衣服的样子么？</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其次，软件工业中我们讲究的是投入和产出比，软件业的成本主要是人力资源的成本。这也是软件项目对时间特别敏感的原因。时间比计划延长一个月，对于一个数十人的团队来说就意味着几十万的成本增加。但是又有谁能够保证自己所做的软件是完美无缺的呢？于是很多时候我们必须对已经开发的部分进行修正，而修正就需要时间。</SPAN> <SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">传统的开发方式下，很多软件项目都是在匆忙交付后发现用户不满意，于是继续修正，再次引发用户的不满意，再次修正，在这样反复地拖延中，客户和软件开发商都筋疲力尽。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们需要迭代开发，是因为我们深知对事物的认知就是一个探索的过程，软件开发也是一样。在温博格《探索需求</SPAN><SPAN lang=EN-US>---</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设计前的质量》一书中提到：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><CITE><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">美国第</SPAN></CITE><CITE><SPAN lang=EN-US style="FONT-SIZE: 10.5pt">34</SPAN></CITE><CITE><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">任总统艾森豪威尔上将曾经说过，</SPAN></CITE><CITE><SPAN lang=EN-US style="FONT-SIZE: 10.5pt">"</SPAN></CITE><CITE><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">计划本身什么都不是，而编制计划的过程就是一切</SPAN></CITE><CITE><SPAN lang=EN-US style="FONT-SIZE: 10.5pt">"</SPAN></CITE><CITE><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">。我们认同这样的说法，并把它推广到需求过程：</SPAN></CITE><CITE><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><BR></SPAN></CITE><CITE><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">　　　　　<B style="mso-bidi-font-weight: normal">　产品什么都不是，而开发的过程就是一切。</B></SPAN></CITE><CITE><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><BR></SPAN></B></CITE><CITE><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">或用另一种方式表达：</SPAN></CITE><CITE><SPAN lang=EN-US style="FONT-SIZE: 10.5pt"><BR></SPAN></CITE><CITE><SPAN style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体">　　　　　　发现什么都不是，而发现过程（探索过程）就是一切。<SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></CITE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><CITE><SPAN lang=EN-US style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体"><o:p>&nbsp;</o:p></SPAN></CITE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">软件项目本身的意义就在于和用户一起探索他们真正需要的东西并且帮助他们实现。而这种探索，如同在第一段中我们阐述的那样，需要不断的反复，如果我们没有做好迭代和反复的准备，而是希望一次性的把所有工作都做完并且还做得非常好，结果可能恰恰相反。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="mso-bidi-font-style: italic"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>我们需要迭代开发，是因为我们追求软件质量的最大化。没有人可以制造出完美无缺的东西，但是我们可以通过不断的检查和反馈，使得那些不适合的东西在早期被暴露出来，迭代给予了我们这样一种检查合反馈的机制，让我们不必在事情结束的时候才惊奇的发现我们所一直努力在做的东西其实是一堆废物。</FONT></SPAN></P>
<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">实践：正确实施迭代开发</SPAN><SPAN lang=EN-US style="mso-fareast-font-family: 宋体"><o:p></o:p></SPAN></FONT></FONT></H1>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">事实上在业界，迭代开发的观念早已经深入人心，然而有多少团队在正确地实施着迭代方法呢？有多少团队通过迭代得到了他们想要的东西呢？很多人简单的把迭代理解为开发的分阶段进行。我们常常看到有项目经理们这样说：我们打算通过</SPAN><SPAN lang=EN-US>4</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">次迭代完成软件的开发，第一次迭代，完成需求分析和软件设计，第二次迭代，完成多少多少模块的开发，第三次，完成其他多少模块的开发，第四次，配置，部署，上线，测试，修正软件</SPAN><SPAN lang=EN-US>bug</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。虽然我们言必称“迭代”，但是这样的迭代和过去传统的瀑布型开发有多少区别？我们又能够从这样的伪迭代中得到什么好处呢？</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>在本文以下部分将对迭代开发实践中几个关键方面进行阐述，这几个方面我们概括为以下关键词：<B style="mso-bidi-font-weight: normal">变化，周期，目标，反馈，合作</B>。</FONT></SPAN></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><FONT size=3><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">变化</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迭代思想带给我们最重要的一个启示，就是要适应变化，要积极、主动地拥抱变化而不是拒绝变化</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>在过去的开发中，我们常常会拒绝变化，以需求分析工作为例，有些项目组在需求分析完成后会要求用户签字，等到交付时，如果客户有什么意见，他们就会拿出那份客户已经签字画押的文件来理直气壮地说：这是你们签字过的东西，我们做的难道不是和这里所说的一样么？</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>是的，开发出来的可能是和需求定义文件的内容一样的，但问题是：这份需求定义文件上描述的内容是不是真正能够帮客户实现自己的价值呢？难道我们进行软件开发的目的就是让客户在一份他们根本不清楚有什么意义的文件上签字，然后用这个来反驳用户的<B style="mso-bidi-font-weight: normal"><SPAN style="COLOR: red">真正需求</SPAN></B>么？我们在软件立项之前总是会告诉用户，这个即将开发的软件会帮助他们如何如何。我们有什么理由为我们做不到这一点而理直气壮地责备客户呢？客户亲笔签名的需求文档难道不是我们整理出来并且讲解给他们听的么？</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>如果一个软件项目的目标是帮助客户实现某一方面的增值，但是这种增值的目的并没有达到，我们就可以认为这个软件项目是失败的。即使软件厂商通过这个项目达到了盈利的目的，满腹牢骚的客户也会把自己的意见传播出去。而如果软件厂商认为这种事情是天经地义的话，那么它在以后的软件项目中也很难帮助自己的客户实现他们想要的价值。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>我们必须让自己具有适应变化的能力。因为这种变化是客户需要的，因为这种变化能够让软件更能体现出自己的价值。我并不是说应该无条件地接受这种变化，但是我们可以在事前就这些问题和客户进行充分的讨论和沟通，让他们明白，世界总是变化的，需求本身可能会变化，而这种变化需要人力和物力的支持。让客户也能够适应自身的变化，这是非常重要的。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>软件开发中的每个人都应该对变化有着充分的准备。从事软件业的人大都充满了自信，系统分析师会认为自己可以把所有的需求搞清楚，设计和开发人员会觉得他们做出来的东西完美地实现了需求。所以，如果我们对一个开发人员说：某某，你过去做的这个模块不能用了，我们现在需要重新做起，通常我们会得到积极或者消极地抵制。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>应该让人们认识到：变化并不是对过去工作的否定，而是着眼于未来，使工作更加完善的必要手段。无论是需求，设计还是程序代码，你不可能一次性就把它们做到完美，而只能通过不断的修正，让它趋近于完美。这个过程就是所谓的“<B style="mso-bidi-font-weight: normal">重构</B>”。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有些团队为了保持开发的稳定性，会</SPAN> <SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">“冻结需求”。所谓的冻结，也就是说在一段时间内要客户方代表承诺不对已经开发中的需求进行变动。如果你打算做这件事情，首先必须意识到，需求本身就是需求，它是不会因为一个承诺就真正地“冻结”了。如果目前的需求定义并不能反映用户真正的愿景，在冻结的周期过去以后我们仍然需要对已经做完的工作进行修改。当然，如果需求变化太频繁，在某些时候有必要对需求进行冻结以便让开发更加平稳，同时也给软件开发者和客户一个反思的时间。但如果是需求分析工作方法有误，那就有必要作一些检讨了。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">要适应变化，我们需要让客户和开发团队有心理上的准备，从而能够以认真的态度来对待它。还需要有正确的方法来应对变化，比如对变化的成本估算，效果的跟踪，如何快速有效的对各种变化进行反映等，这是我们必须注意的问题。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial"><FONT size=3>周期</FONT></SPAN></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">很多人简单的把迭代理解为开发的分阶段进行。有些项目经理会这样说：我们打算通过</SPAN><SPAN lang=EN-US>4</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">次迭代完成软件的开发，第一次迭代，完成需求分析和软件设计，第二次迭代，完成多少多少模块的开发，第三次，完成其他多少模块的开发，第四次，配置，部署，上线，测试，修正软件</SPAN><SPAN lang=EN-US>bug</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。在这里，虽然他们言必称“迭代”，但是这样的迭代和过去传统的瀑布型开发有多少区别？</SPAN> <SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>迭代开发是要分周期分阶段地进行，但是不能认为简单地把开发周期划分为几个不同的阶段就是迭代。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">很多人对于迭代周期有一些误解，比如：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l2 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>n</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>认为迭代只适用于开发阶段，而需求分析和设计工作则不在此范围内。</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo2; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>n</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>认为迭代周期可以拉得很长，比如两个月，三个月，甚至一个季度，半年。</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo3; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>n</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>将需求分析，设计，开发，测试，部署，用户反馈，修改当作完整的迭代周期，并要求在前一阶段工作完全（或者大部分）完成以后再进行下一步工作（迭代）。</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>在一个迭代周期内，我们可以做什么事情呢？可以说：所有的事情。如果你认为迭代需要在需求分析完成之后才能开始，或者系统集成必须在所有迭代完成之后才可以进行，你会获得一个真正的瀑布流程开发。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>一个迭代周期意味着对一些特定功能（用例）的探索。“探索”一词可能随情况不同而有不同的含义。对于抽象级别较高，模糊程度比较高的用例，我们需要通过和用户的讨论将它逐渐分解为更加清楚和清晰的用例。对于目前我们认为已经得到了详细定义的需求，需要选取合适的部分进行设计和实现，通过这些部分的实现，对需求定义和技术可行性进行反馈。对那些在上次迭代中已经开发完的模块，应该尽可能快速地让用户提出他们的意见，以便了解是否真正解决了用户面临的问题，以及还有没有可以改进的方面，再根据这些意见安排下一阶段的工作。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>我们是否可以在开发进行之前把需求或者设计全部弄清楚呢？我认为很难。因为通常来讲，用户对于自己的需求只有一个模糊的概念。让我们假设一个饮食业的例子，有一天餐厅经理把你叫入办公室说：马上设计一个新的菜谱，这个菜谱是为某某特定人群定制的，你要让这些人感觉色香味俱全。不过在你把配料和烹调方法都设计出来之前，我们不打算让大厨来具体做这道菜，我们不允许失败，所以你的设计一定要一次成功，你可以用调查问卷，用户面谈等方法获取最终用户的需求，但是记住：你不能去做这道菜。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这样的事情你可能会觉得很滑稽，但是在软件业，类似的事情人们却认为是天经地义的。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迭代允许我们将开发本身也作为需求探索的一部分</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，通过用户对已经实现功能的反馈我们和用户都会逐渐明白什么样的软件是我们最终想要开发的。所以，不要等到所有（或者大部分）的分析完了才开始开发，而是尽早对已经捕获到的需求进行细化，尽早开发，以获得反馈。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>在安排迭代计划时，应该指明，这次迭代的目标是什么，在结束时应达到的里程碑是什么。如果有任务提前达到了这个里程碑，我们可以提前结束迭代，或者顺便在剩下的时间内安排其他的任务，但是要注意这种安排的合理性，不要因为这个而使得迭代周期被延长。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在一次迭代到达所设定的结束日期时，就必须审视各项任务是否达到了里程碑的要求，如果有任务没有达到，原因是什么，我们是否需要对需求和技术方案做出调整。对于没有达到里程碑要求的任务，我们可以采取的办法有两种：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo3; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>n</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>将剩余的工作列入下一次迭代计划中去，</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo3; tab-stops: list 75.0pt"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN style="mso-list: Ignore"><FONT size=2>n</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>将本次迭代的结束时间向后延迟，等待任务的完成</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>前一种办法适合于有很大工作量没有完成的情况，这可能也同时说明计划的制定有问题，在制定下次迭代计划时应该考虑对任务完成时间进行调整。后一种办法适合剩余工作量不是很大的情况。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">通常来说，一次迭代完成以后应该有一个产品的新版本可用。这也就意味着：将集成和发布分散到每次迭代中去。借助于一些自动化工具（比如</SPAN><SPAN lang=EN-US>ant</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">），我们甚至可以做到每日构建。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一个迭代周期应该有多长呢？这并没有一个统一的说法，而是应该视目标和可用的资源而定。但是，迭代周期不宜过长，也不宜过短。迭代周期过长的话，会延缓反馈的时间，可能将许多问题隐藏或是堆积了起来。迭代周期过短，会让人身心疲劳，事情难有大的成效。一般来说，迭代周期应该在</SPAN><SPAN lang=EN-US>2-6</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">周之间。如果安排的迭代周期超过了两个月，你可能就必须审视一下迭代计划的合理性了。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>不要认为下一次迭代应该和上次迭代的时间差不多，刻板地把所有迭代规定一个统一的时间是一个很坏的做法。但是你可以把以前迭代周期中的工作效率作为估算下次迭代时间的一个依据。</FONT></SPAN></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial"><FONT size=3>目标</FONT></SPAN></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>一次迭代必须有明确的目标：我们希望通过这次迭代达到什么目的。在制定目标时，应该同时考虑另外一个问题：如何检查该目标是否已经达成。这就是所谓的“里程碑”。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">迭代计划必须有明确而可行的目标。明确的意思是它应该是<B style="mso-bidi-font-weight: normal">可度量</B>的，不能太模糊，因为你很难检查一个模糊的目标是否达成。比如，我们可以说，这次迭代的目标是对</SPAN><SPAN lang=EN-US>xxx</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">方面的需求作进一步细化和评审，完成</SPAN><SPAN lang=EN-US>xxx</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">模块的开发以加入到软件的下一版本中去。这样的目标是明确而且可行的。反过来，如果我们这样说：我们要通过和用户的讨论明确绝大部分愿景，同时要有一个初步的开发。“绝大部分”和“初步”这样的词让人感到困惑：多少是绝大部分呢，在总量尚未明确的前提下，怎么能够知道完成的确是“绝大部分”而不是“一小部分”？“初步的开发”似乎告诉我们这次开发量比较小，但是具体开发哪个部分，或者开发到什么程度，并没有指出一个明确的概念。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">由此产生了一个困惑，软件项目是一个不断探索的过程，我们怎么能够明确地对未来的事情作安排呢？譬如在项目初始调查用户愿景时，为了实现“明确”的目标，是否这样定义任务：完成</SPAN><SPAN lang=EN-US>20%</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的用户愿景调查？</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">很显然，用户愿景总量到底有多少我们并不知道，所以在这次迭代完成以后如果我们问：是否真的完成了</SPAN><SPAN lang=EN-US>20%</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">而不是</SPAN><SPAN lang=EN-US>15%</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">？很难得到答案。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为了避免出现这种情况，你必须换个角度来看问题，比如我们可以说：对</SPAN><SPAN lang=EN-US>xxx</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">部门和</SPAN><SPAN lang=EN-US>yyy</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">部门的用户做愿景调查。在迭代完成后，可以检查是否这两个部门所有用户的访谈，调查都已经完成，是否这些部门每个人都认为自己表达了全部的意思。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>所以，如果你发现很难对制定的目标进行度量，那么换一个角度来看事情吧，你可能就会找到一个合适的表达方式。如果你从所有的角度都看不到事情是可以度量的，那么这可能意味着这件事情可能还没有到应该去实施的地步，这时你应该把它从迭代计划中去掉。对于这种情况，有人可能会说：那我们这次迭代可做的事情就很少了，如果真是这样，那就进行一次小的迭代吧，可能把这次迭代的工作做完了以后就会有更多的工作可以安排了。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>有些项目经理在日程表上，很详细地写着：第一次迭代，某月某日到某月某日，第二次迭代：某月某日到某月某日，第三次迭代。。。这样的做法是不恰当的。因为它假设了后面几次迭代的任务量，但是实际上，在前面的工作完成之前，你很难对以后的工作得到一个明确地概念。而且在这样的计划上，可能并没有用于测量迭代成果的里程碑，这样的迭代最后很可能会演变成为瀑布式的开发。所以，在一次迭代完成之前，不要对急着去计划下次迭代，特别是不要试图精确定义下次迭代的时间，因为你连下次迭代要做什么都还不清楚。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>为什么目标的可度量性这么重要呢？在团队开发中，很多信息因为人与人的交流不畅而无法得到正确地反馈，这让我们没有办法实时地掌握项目的进展情况，退而求其次，我们必须阶段性地了解这些信息。如果目标难以度量，迭代结束后我们很难明确到底有哪些工作没有完成，也就无法看到事情的问题所在。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>有些团队中会要求每个成员每天对自己的工作进度以百分比的形式做汇报，他们以为通过这样的方式可以确实的掌握事情的进展，但实际上并不行，因为软件开发中存在很多不确定因素，有时候我们认为事情已经完成了一大半，但是可能因为技术或者其他的原因发现这一大半工作方向是错的，这时候就要推倒重来，而且人们在汇报工作量的时候总是会有一些感情的因素在里面，这就使那些看似精确的百分比打了个折扣。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>所以，我们需要更加实际和细致地划分工作，对目标的完成情况进行度量。这也是迭代周期不能太长的一个原因：如果你把大量有前后关联的工作划分入一个迭代周期，在设定的结束到来时，突然发现只完成了一小部分，这时候虽然亡羊补牢仍然可以，但是中间浪费了大量的人力和物力。</FONT></SPAN></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial"><FONT size=3>反馈</FONT></SPAN></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>一个男人在大街上走着，他并没有发现裤子上的拉链已经松开了，虽然看到这个情况的人有很多，但他们有各种各样的担心，比如不想多管闲事，怕让那个男人难堪，或者干脆就是想看笑话。结果就是这个人继续穿着一条敞开拉链的裤子在大街上行走。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">这件事情至少带给我们两个启示：</SPAN><SPAN lang=EN-US>1</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，得到反馈是重要的；</SPAN><SPAN lang=EN-US>2</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，要想得到正确的，有价值的反馈，你需要其他人的配合。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>对于用户需求来说，没有用户及时地反馈，我们就可能把那些不符合需求的开发继续下去，由于软件中各种功能和模块的依赖性，这种不符合最后可能被放大到数倍。越迟得到反馈，问题可能就越大。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>软件开发中一个很重要的概念是“可行性”和“合理性”，无论我们做需求，设计还是开发，集成，测试，都会遇到这两个问题。有些事情的可行性和合理性是我们可以通过事前的分析进行判断的，但是有些问题就必须有一定的实践作为基础。这也是一个反馈的问题。譬如说在某项目中技术架构师决定采取一个技术架构，但是经过一些阶段的开发发现它有一些技术上问题不能实现用户的关键需求，这时候就必须放弃它。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><B style="mso-bidi-font-weight: normal"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">“反馈”意味着两个意思，对一件事情的调查和根据调查做出决策。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></B></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>在意识到反馈的重要性之后，你会要求所有的人都对迭代的成果做出反馈。可能存在的问题是，是不是所有的人都意识到了反馈的重要性并且认真地去做了呢？如果客户认为他们只需要对迭代出来的产品“看看而已”，那么你就很难了解他们一些深层次的想法。再比如一次迭代中某些模块开发的进度比较慢，开发人员可能会抱怨技术方案不能满足要求，而实际的原因可能是设计不合理或者根本就是有人没有认真工作。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>中国国家队前主教练米卢曾经说过“态度决定一切”，反馈作为迭代开发中至关重要的一个方面，必须得到足够的重视。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>获得反馈的方式和对于反馈信息的分析是另外一个重要的方面。一般来讲，根据软件开发角色的不同，我们非常关注的是两类人的反馈：项目组之外的客户和项目组之内的各种实施人员。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>软件项目一般都会要求客户方安排专门的业务人员进行配合，在迭代开发中，这种配合不只是进行需求的整理和发掘，还包括对已经完成软件版本的评测。在这个过程中应该有需求分析师的配合。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>在每次迭代完成之后，软件项目组应该有一些总结和分析活动。通过这些总结和分析，找到做得好和做得不好的方面。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>在非迭代式的开发中，也有反馈的环节。比如通常在软件交付阶段会有一个试用期让用户提出意见。而软件团队在各种开发中都会有一些总结活动。迭代式开发的独特之处在于尽量早地引入反馈机制；使得反馈机制更加制度化；并且，更加快速和灵活地分析这些反馈，把得到的结论应用到下一阶段的开发中去。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>对于一些机制引起的问题，比如组织结构不合理，角色分配不明确之类。最好有一个明确的问题记录表。在每次迭代完成以后将这些问题记录下来，同时在下次迭代中努力改善它。如果相同的问题连续出现在几次迭代中，可能就说明项目管理出了问题。</FONT></SPAN></P>
<H2 style="MARGIN: 7pt 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial"><FONT size=3>合作</FONT></SPAN></H2>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>软件团队中的合作是人们一直都在提倡的。我们在这里提到“合作”的意思并不只包含团队内部的协作，还包括和客户的合作。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>迭代开发需要快速反应，这需要各种不通角色人员的配合。如果人们做事情总是拖拖拉拉，就会延缓软件项目的进度。而且每个人对自己在迭代中应该做什么事情必须很清楚，这需要事前的准备和角色的合理分配。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>迭代需要用户的配合，实际上最好能够有客户方<B style="mso-bidi-font-weight: normal">真正的系统使用者</B>参加到迭代过程中来，因为他们是最有发言权的。很多项目中会让项目经理或是系统分析师担当客户代表的角色，这样做有很多弊病。有时出于各种原因客户确实不能到现场配合的，我们也可以通过其他的途径获得客户反馈。比如一个阶段迭代完成以后，可以把相关操作用截屏加文字说明的方式发给客户，让他们对产品有一个直观的印象。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为了让团队能够有效快速地配合，应该尽可能使用各种自动化工具</SPAN></B><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。比如自动化测试管理工具，以及配置管理，集成以及发布之类的工具。通过对这些工具的有效应用，使得各个成员能够快速获得信息。</SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>迭代开发要拥抱变化，主动适应变化。要让每个参与者都认识到这一点：不能够固步自封，或者满足于现有的成就，不去思考可改进的地方。从管理者的角度上，必须重视每一个反馈信息。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>迭代开发追求对任务的度量。很多组织会把这种度量和员工的绩效考评联系起来。这种做法可能是合适的，但是如果只是简单衡量工作量或者工作完成速度和质量，有可能会比较片面。毕竟软件开发是一个环环相扣的过程，表面上来看这个环节处理不好，实际上可能是准备工作做得不好，或者其他人的配合不好。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以如果在迭代过程中出现了问题，一定要客观地分析，特别是应该挖掘导致这些问题出现的深层次原因。譬如在一次迭代中测试人员发现了一些</SPAN><SPAN lang=EN-US>bug</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">，但是两次迭代过去了，这些</SPAN><SPAN lang=EN-US>bug</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">仍然存在，这就说明对</SPAN><SPAN lang=EN-US>bug</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的处理不够迅速（当然如果因为某些原因这些事情被故意推迟了的情况不算）。这时就必须分析一下到底是什么原因造成了信息的不通畅。而不能简单地批评相关责任人。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></P>
<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial">总结</SPAN><SPAN lang=EN-US style="mso-fareast-font-family: 宋体"><o:p></o:p></SPAN></FONT></FONT></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>本文对迭代开发的五个关键（变化，周期，目标，反馈，合作）方面进行了讨论。作为一种方法论，迭代开发的好处在于它使软件团队变得更加灵活。在实施迭代开发的过程中，应注意不能流于形式化，切实做好每个环节的工作，这样才能获得满意的结果。</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US><FONT size=2>Email:jayliu@mail.csdn.net</FONT></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US><A href="http://www.blogjava.net/jayliu"><FONT size=2>http://www.blogjava.net/jayliu</FONT></A><o:p></o:p></SPAN></P><img src ="http://www.blogjava.net/jayliu/aggbug/4283.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-14 10:08 <a href="http://www.blogjava.net/jayliu/archive/2005/05/14/4283.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Google Toolbar的翻译功能</title><link>http://www.blogjava.net/jayliu/archive/2005/05/14/4278.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Sat, 14 May 2005 00:52:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/14/4278.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4278.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/14/4278.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4278.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4278.html</trackback:ping><description><![CDATA[<P>前两天浏览网页时偶然地把鼠标在一个字上面放了一会，结果居然被翻译了出来。仔细一看，发现不是金山词霸的原因。还一直以为是ie附加了翻译功能。结果今天偶然地隐藏了google Toolbar，发现翻译功能不能用了。这才恍然大悟。<BR><BR></P><IMG src="http://img64.photo.163.com/jayliu2000/8673209/186638867.jpg"><img src ="http://www.blogjava.net/jayliu/aggbug/4278.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-14 08:52 <a href="http://www.blogjava.net/jayliu/archive/2005/05/14/4278.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ejb3.0的几点显著特性</title><link>http://www.blogjava.net/jayliu/archive/2005/05/12/4241.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 12 May 2005 13:38:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/12/4241.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4241.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/12/4241.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4241.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4241.html</trackback:ping><description><![CDATA[<P class=MsoList style="MARGIN: 0cm 0cm 11pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman"><FONT size=2>1.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>元数据的引入：以注释的形式表示元数据，取代了过去大量的配置文件</FONT></SPAN></P>
<P class=MsoList style="MARGIN: 0cm 0cm 11pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman"><FONT size=2>2.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">各种</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">enterprise bean</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的定义都只需要定义一些</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">POJO</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">POJI</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">配合元数据即可完成</SPAN></FONT></P>
<P class=MsoList style="MARGIN: 0cm 0cm 11pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman"><FONT size=2>3.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">回调机制（</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">callback</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">）也是用普通的方法加以一定的注释，代替了原有的</SPAN><SPAN lang=EN-US><FONT face="Times New Roman">ejbCreate</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">之类的方法</SPAN></FONT></P>
<P class=MsoList style="MARGIN: 0cm 0cm 11pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><FONT face="Times New Roman"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT size=2>4.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN lang=EN-US><FONT size=2>AOP</FONT></SPAN></FONT><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>概念的引入：允许在类定义中和其他类中对方法进行拦截</FONT></SPAN></P>
<P class=MsoList style="MARGIN: 0cm 0cm 11pt 75pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 75.0pt"><SPAN lang=EN-US style="mso-fareast-font-family: 'Times New Roman'"><SPAN style="mso-list: Ignore"><FONT face="Times New Roman"><FONT size=2>5.</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></FONT></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><FONT size=2>依赖注入：允许通过添加特定注释向属性注入所依赖的对象<BR><BR>总的来说，ejb3.0相对于ejb2.0来说实现更加简单了，甚至我认为比目前的一些轻量级解决方案（比如spring framework之类）还要简单。</FONT></SPAN></P><img src ="http://www.blogjava.net/jayliu/aggbug/4241.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-12 21:38 <a href="http://www.blogjava.net/jayliu/archive/2005/05/12/4241.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2SE5.0新特性示例---循环语句的增强</title><link>http://www.blogjava.net/jayliu/archive/2005/05/12/4202.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 12 May 2005 02:57:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/12/4202.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4202.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/12/4202.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4202.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4202.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial"><FONT style="BACKGROUND-COLOR: #e5e5e5" size=3>循环语句的增强</FONT></SPAN></H1><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">之前类似这样的语句：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>void cancelAll(Collection c) { <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>for (Iterator i = c.iterator(); i.hasNext(); ) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>TimerTask tt = (TimerTask) i.next();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>tt.cancel();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'">}</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P></TD></TR></TBODY></TABLE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">以后可以这样写：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>void cancelAll(Collection c) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>for (Object o : c)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>((TimerTask)o).cancel();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT color=#000000><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">有时候我们可能写出这样的代码：</SPAN></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>List suits = ...;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>List ranks = ...;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>List sortedDeck = new ArrayList();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>for (Iterator i = suits.iterator(); i.hasNext(); )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>for (Iterator j = ranks.iterator(); j.hasNext(); )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>sortedDeck.add(new Card(i.next(), j.next()));<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN lang=EN-US><o:p><FONT face="Courier New" color=#0000ff>&nbsp;</FONT></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT color=#000000><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">这段代码不会按照我们设想的那么工作，因为每次第二个</SPAN><SPAN lang=EN-US><FONT face="Courier New">for</FONT></SPAN></SPAN><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">语句的执行都会引发</SPAN><SPAN lang=EN-US><FONT face="Courier New">i.next()</FONT></SPAN></SPAN><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">的执行，实际上我们没有达到对</SPAN><SPAN lang=EN-US><FONT face="Courier New">i</FONT></SPAN></SPAN><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">进行遍历的目的，而且可能会引起一个</SPAN><SPAN lang=EN-US><FONT face="Courier New">NoSuchElementException</FONT></SPAN></SPAN><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">异常。</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT color=#000000><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">解决的一个办法是改写成如下代码：</SPAN></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>for (Iterator i = suits.iterator(); i.hasNext(); ) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>Suit suit = (Suit) i.next();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>for (Iterator j = ranks.iterator(); j.hasNext(); )<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>sortedDeck.add(new Card(suit, j.next()));<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'">}</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P></TD></TR></TBODY></TABLE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN lang=EN-US><o:p><FONT face="Courier New" color=#0000ff>&nbsp;</FONT></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT color=#000000><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">利用</SPAN><SPAN lang=EN-US><FONT face="Courier New">java</FONT></SPAN></SPAN><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">语言的新特性，我们可以这样写：</SPAN></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>for (Suit suit : suits)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>for (Rank rank : ranks)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>sortedDeck.add(new Card(suit, rank));<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><SPAN lang=EN-US><o:p><FONT face="Courier New" color=#0000ff>&nbsp;</FONT></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN class=CharCharCharCharCharCharCharCharCharCharCharCharCharCharCharChar><FONT color=#000000><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'">这段代码是不是很漂亮？</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"></SPAN></FONT></P><img src ="http://www.blogjava.net/jayliu/aggbug/4202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-12 10:57 <a href="http://www.blogjava.net/jayliu/archive/2005/05/12/4202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2SE5.0新特性示例---枚举</title><link>http://www.blogjava.net/jayliu/archive/2005/05/12/4206.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 12 May 2005 02:57:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/12/4206.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4206.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/12/4206.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4206.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4206.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">枚举</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></FONT></FONT></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">在过去，我们必须用整型常数代替枚举，随着</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">J2SE 5.0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的发布，这样的方法终于一去不复返了。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">一个简单的枚举类型定义如下：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>public enum Weather<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>SUNNY,RAINY,CLOUDY<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">枚举可以用在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">switch</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">语句中：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>Weather weather=Weather.CLOUDY;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>switch(weather)<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>case SUNNY:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.out.println("It's sunny");<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>break;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>case CLOUDY:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.out.println("It's cloudy");<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>break;<SPAN style="mso-tab-count: 1"> </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>case RAINY:<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>System.out.println("It's rainy");<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>break;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">枚举类型可以有自己的构造方法，不过必须是私有的，也可以有其他方法的定义，如下面的代码：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>public enum Weather {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>SUNNY("It is sunny"),<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>RAINY("It is rainy"),<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>CLOUDY("It is cloudy");<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>private String description;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>private Weather(String description) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>this.description=description;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>public String description()<SPAN style="mso-tab-count: 1"> </SPAN>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return this.description;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">下面一段代码是对这个枚举的一个使用：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>for(Weather w:Weather.values())<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>{<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN>System.out.printf(<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>"Description of %s is \"%s\".\n",w,w.description());<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>Weather weather=Weather.SUNNY;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>System.out.println(weather.description() + " today");<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">如果我们有一个枚举类型，表示四则运算，我们希望在其中定义一个方法，针对不同的值做不同的运算，那么我们可以这样定义：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>public enum Operation {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>PLUS, MINUS, TIMES, DIVIDE;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>// Do arithmetic op represented by this constant<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>double eval(double x, double y){<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>switch(this) {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>case PLUS:<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>return x + y;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>case MINUS:<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>return x - y;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>case TIMES:<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>return x * y;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>case DIVIDE: return x / y;<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>throw new AssertionError("Unknown op: " + this);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">这样写的问题是你如果没有最后一行抛出异常的语句，编译就无法通过。而且如果我们想要添加一个新的运算，就必须时刻记着要在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">eval</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中添加对应的操作，万一忘记的话就会抛出异常。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">J2SE 5.0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">提供了解决这个问题的办法，就是你可以把</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">eval</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">函数声明为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">abstract</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">，然后为每个值写不同的实现，如下所示：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>public enum Operation {<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>PLUS<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>{ double eval(double x, double y) { return x + y; } },<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>MINUS<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>{ double eval(double x, double y) { return x - y; } },<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>TIMES<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>{ double eval(double x, double y) { return x * y; } },<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>DIVIDE { double eval(double x, double y) { return x / y; } };<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2><SPAN style="mso-tab-count: 1">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>abstract double eval(double x, double y);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>}<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">这样就避免了上面所说的两个问题，不过代码量增加了一些，但是随着今后各种</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">开发</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"> IDE</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的改进，代码量的问题应该会被淡化。</SPAN></FONT><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P><img src ="http://www.blogjava.net/jayliu/aggbug/4206.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-12 10:57 <a href="http://www.blogjava.net/jayliu/archive/2005/05/12/4206.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2SE5.0新特性示例---原生类型的autoboxing和auto-unboxing</title><link>http://www.blogjava.net/jayliu/archive/2005/05/12/4205.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 12 May 2005 02:57:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/12/4205.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4205.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/12/4205.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4205.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4205.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN lang=EN-US><FONT face=Arial></FONT></SPAN></FONT></FONT>&nbsp;</H1><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">
<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">原生类型的</SPAN><SPAN lang=EN-US><FONT face=Arial>autoboxing</FONT></SPAN><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">和</SPAN><SPAN lang=EN-US><FONT face=Arial>auto-unboxing</FONT></SPAN></FONT></FONT></H1>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">我们知道，在</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">中，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">int,long</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">等原生类型不是一个继承自</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Object</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">的类，所以相应的，有很多操作我们都不能利用原生类型操作，比如想要把一个整数放入到一个集合中，我们必须首先创建一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Integer</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象，然后再将这个对象放入到集合中。当我们从集合中取数的时候，取出来的是一个</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Integer</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">对象，因此不能直接对它使用加减乘除等运算符，而是必须用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Integer.intValue()</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">取到相应的值才可以，这样的过程称之为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">boxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">unboxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">J2SE5.0</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">支持</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">autoboxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">auto-unboxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">，也就是说我们以后不需要再手动地做这些</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">boxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">unboxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">操作了，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">java</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">语言会替我们完成。具体可以参照下面的示例：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt">
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>List&lt;Integer&gt; intList=new ArrayList&lt;Integer&gt;();<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>intList.add(2);<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>intList.add(new Integer(5));<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>int i=3+intList.get(0);//i=5<o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>int j=3+intList.get(1); //j=8<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">从这一段程序中我们可以看到，</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">autoboxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">和</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">auto-unboxing</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">为我们省掉了很多不必要的工作。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></P>
<P class=MsoBodyText style="MARGIN: 0cm 0cm 11pt 54pt"></SPAN></FONT></P><img src ="http://www.blogjava.net/jayliu/aggbug/4205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-12 10:57 <a href="http://www.blogjava.net/jayliu/archive/2005/05/12/4205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>J2SE5.0新特性示例---静态引入</title><link>http://www.blogjava.net/jayliu/archive/2005/05/12/4207.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 12 May 2005 02:56:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/12/4207.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4207.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/12/4207.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4207.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4207.html</trackback:ping><description><![CDATA[<H1 style="MARGIN: 11pt 0cm"><FONT size=3><FONT style="BACKGROUND-COLOR: #e5e5e5"><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">静态引入（</SPAN><SPAN lang=EN-US><FONT face=Arial>static import</FONT></SPAN><SPAN style="FONT-FAMILY: 黑体; mso-ascii-font-family: Arial">）</SPAN><SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></FONT></FONT></H1>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">在过去我们要使用其他包中某类的静态变量，一般都要在前面加上对应的类名：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'">double r = Math.cos(Math.PI * theta);</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">使用静态引入，我们可以把前面的类名去掉，静态引入的语句是这样的：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>import static java.lang.Math.PI;<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">必须注意到这里最后不是到类</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">Math,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">而是直接到了定义的变量</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">PI</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><FONT size=2><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">静态引入不只对静态变量，也可以针对静态方法。此外还可以使用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'">*</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">，如下面所示：</SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p></o:p></SPAN></FONT></P>
<TABLE class=MsoTableGrid style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BACKGROUND: silver; MARGIN: auto auto auto 59.4pt; BORDER-LEFT: medium none; WIDTH: 378pt; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellSpacing=0 cellPadding=0 width=504 border=1>
<TBODY>
<TR style="mso-yfti-irow: 0; mso-yfti-lastrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 378pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" vAlign=top width=504>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: 'Courier New'"><FONT size=2>import static java.lang.Math.*;<o:p></o:p></FONT></SPAN></P></TD></TR></TBODY></TABLE>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'"><o:p><FONT size=2>&nbsp;</FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 54pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'; mso-bidi-language: AR-SA"><FONT size=2>除非我们对某个静态常量（或者方法）访问频度很大，否则应该尽量避免使用静态引入。</FONT></SPAN><SPAN lang=EN-US style="FONT-FAMILY: 'Courier New'; mso-bidi-language: AR-SA"><o:p></o:p></SPAN></P><img src ="http://www.blogjava.net/jayliu/aggbug/4207.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jayliu/" target="_blank">幻</a> 2005-05-12 10:56 <a href="http://www.blogjava.net/jayliu/archive/2005/05/12/4207.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>