﻿<?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/category/1271.html</link><description>We are extremely fortunate not to know precisely the kind of world we live in </description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 12:38:16 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 12:38:16 GMT</pubDate><ttl>60</ttl><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>3</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>5</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>1</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>1</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>2</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>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新特性示例---原生类型的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/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新特性示例---静态引入</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><item><title>J2SE5.0新特性示例---元数据</title><link>http://www.blogjava.net/jayliu/archive/2005/05/12/4209.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/4209.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4209.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/12/4209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4209.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4209.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: J2SE 5.0通过引入注释(Annotation)的概念添加了对元数据的支持。一个@xxx形式的注释可以当成一个修饰符来使用，它可以放在任何一个修饰符可以出现的地方。public,static,final都是java语言的修饰符，注释可以写在它们可以出现的任何地方。举个例子，可以看下面一段代码：public class AnnotationExample {&nb...&nbsp;&nbsp;<a href='http://www.blogjava.net/jayliu/archive/2005/05/12/4209.html'>阅读全文</a><img src ="http://www.blogjava.net/jayliu/aggbug/4209.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/4209.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/4203.html</link><dc:creator>幻</dc:creator><author>幻</author><pubDate>Thu, 12 May 2005 02:55:00 GMT</pubDate><guid>http://www.blogjava.net/jayliu/archive/2005/05/12/4203.html</guid><wfw:comment>http://www.blogjava.net/jayliu/comments/4203.html</wfw:comment><comments>http://www.blogjava.net/jayliu/archive/2005/05/12/4203.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jayliu/comments/commentRss/4203.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jayliu/services/trackbacks/4203.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 简介泛型其实并不是一种新的语言元素，C++中早就就有，但是在C++之后的java却没有吸收这个特性，现在Java也有了泛型的特性，大概也和.Net的竞争有关系吧。首先看泛型的一个应用。在过去，我们可能经常要写一些类似这样的代码：List stringList=new LinkedList();stringList.add("firstString");str...&nbsp;&nbsp;<a href='http://www.blogjava.net/jayliu/archive/2005/05/12/4203.html'>阅读全文</a><img src ="http://www.blogjava.net/jayliu/aggbug/4203.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:55 <a href="http://www.blogjava.net/jayliu/archive/2005/05/12/4203.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>