??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品综合久久网各,亚洲成a人片在线观看精品,一本久到久久亚洲综合http://m.tkk7.com/bounce/zh-cnMon, 12 May 2025 18:48:56 GMTMon, 12 May 2025 18:48:56 GMT60Got Source Code of Kettlehttp://m.tkk7.com/bounce/archive/2008/09/15/229009.htmlJ2SJ2SMon, 15 Sep 2008 10:24:00 GMThttp://m.tkk7.com/bounce/archive/2008/09/15/229009.htmlhttp://m.tkk7.com/bounce/comments/229009.htmlhttp://m.tkk7.com/bounce/archive/2008/09/15/229009.html#Feedback3http://m.tkk7.com/bounce/comments/commentRss/229009.htmlhttp://m.tkk7.com/bounce/services/trackbacks/229009.html  Using Kettle for more than one year in my project, but still have no time to read the source code of Kettle untill couple of days before (busy or actually lazy?). Yeah, I am a lazy dog...
  Since the source code is not available directly from the Pentato website, I had no choice but to go thru some posts on the Pentaho forum one by one. It didn't take me much effor before I found the relevant post, thx god:) The source code of Kettle now is maintained in SVN of JavaForge, and anybody "can get the latest(subversion trunk) code changes with on this URL: http://svn.javaforge.com/svn/Kettle/trunk", the username is "anonymous" and password is "anon".
  Besides, I had to download a SVN tool. I am using TortoiseSVN in my company, and the ux satisfied me, so I chose it again.
  It taked about 30 minutes to check out all the source code (still very fast I think, my bandwidth is 2M).
  When it done, I imported it as a general project into eclipse, and one thing surprised me a little bit was that, I didn't have to compile the source code or import some jars even than execute a Ant target manually as I built the source code of Spring before. Hah, Kettle is developed by using eclipse?! (you can find some eclipse project files in the trunk).
  Anyway, the work was going on smoothly, no more than 40 minutes. Now I can debug the Kettle, and from my experience, in some scenarios Kettle doesn't work in good performace than I expect, and even sometimes it runs into some bugs when I do the multitudinous insert or update operations. Here I get the opportunity to look into the code and figure out the problem.

  Keep moving forward...



J2S 2008-09-15 18:24 发表评论
]]>
集合框架cȝ记的补充http://m.tkk7.com/bounce/archive/2007/03/19/104831.htmlJ2SJ2SMon, 19 Mar 2007 14:04:00 GMThttp://m.tkk7.com/bounce/archive/2007/03/19/104831.htmlhttp://m.tkk7.com/bounce/comments/104831.htmlhttp://m.tkk7.com/bounce/archive/2007/03/19/104831.html#Feedback1http://m.tkk7.com/bounce/comments/commentRss/104831.htmlhttp://m.tkk7.com/bounce/services/trackbacks/104831.html java .util.*定义?jin)一pd的接口和c,告诉我们用什么类NEWZ个对象,可以q行越数组的操作?
Q注Q?b style="COLOR: black; BACKGROUND-COLOR: #ffff66">JAVA1.5?b style="COLOR: black; BACKGROUND-COLOR: #ffff66">JAVA1.4的最大改q就是增加了(jin)对范型的支持Q?br />
Set接口是数学中集合的概念:(x)其元素无序,且不可重复。(正好与List对应Q?br />
!!注意数组和集合的区别Q数l中只能存简单数据类型。Collection接口和Map接口只能存对象?

只有List可用get和size。而Set则不可用Q因其无序)(j)?

集合中每一个元素都有对象,如有字符串要l过强制cd转换?

Collections是工L(fng)Q所有方法均为有用方法,且方法ؓ(f)static?


Collections.Sort()分ؓ(f)两部分,一部分为排序规则;一部分为排序算法?
规则用来判断对象Q算法是考虑如何排序?
对于自定义对象,Sort不知道规则,所以无法比较。这U情况下一定要定义排序规则。方式有两种Q?
?java.lang下面有一个接口:(x)ComparableQ可比较的)(j)
可以让自定义对象实现一个接口,q个接口只有一个方法comparableTo(Object o)
其规则是当前对象与o对象q行比较Q其q回一个int|pȝҎ(gu)此值来q行排序?
?当前对象>o对象Q则q回?gt;0Q(可将q回值定义ؓ(f)1Q?
?当前对象=o对象Q则q回?0Q?
?当前对象<o对象Q则q回倹{?。(可将q回值定义ؓ(f)-1Q?
看TestArraylist?b style="COLOR: black; BACKGROUND-COLOR: #ffff66">java代码?
我们通过q回??1位置的调换来实现升序和降序排列的转换?

?java.util下有一个Comparator(比较?
它拥有compare()Q用来比较两个方法?
要生成比较器Q则用Sort中SortQList,List(Compate)Q?
W二U方法更灉|Q且在运行的时候不用编译?

注意Q要惛_现comparTo()必dL法中写上implement comparable.


集合的最大缺Ҏ(gu)无法q行cd判定Q这个缺点在JAVA1.5中已l解冻I(j)Q这样就可能出现因ؓ(f)cd不同而出现类型错误?
解决的方法是dcd的判断?br />
而在LinkedList的底层是一U双向@环链表。在此链表上每一个数据节炚w׃部分l成Q前指针Q指向前面的节点的位|)(j)Q数据,后指针(指向后面的节点的位置Q。最后一个节点的后指针指向第一个节点的前指针,形成一个@环?br />
LinkedListl常用在增删操作较多而查询操作很的情况下:(x)队列和堆栈?
队列Q先q先出的数据l构?
堆栈Q后q先出的数据l构?
注意Q用堆栈的时候一定不能提供方法让不是最后一个元素的元素获得出栈的机?x)?
LinkedList提供以下Ҏ(gu)Q(ArrayList无此cL法)(j)
addFirst();
removeFirst();
addLast();
removeLast();


Push用addFirst()Qpop用removeFirst()Q实现后q先出?
用isEmpty()--其父cȝҎ(gu)Q来判断栈是否ؓ(f)I?

在队列中Qput为入队列操作Qget为出队列操作?
Put用addFirst()Qget用removeLast()实现队列?br />
List接口的实现类QVectorQ(与ArrayList怼Q区别是Vector是重量的组Ӟ使用使消耗的资源比较多。)(j)
l论Q在考虑q发的情况下用VectorQ保证线E的安全Q?
在不考虑q发的情况下用ArrayListQ不能保证线E的安全Q?

面试l验Q知识点Q:(x)
java.util.stackQstack即ؓ(f)堆栈Q的父类为Vector。可是stack的父cL最不应该ؓ(f)Vector的。因为Vector的底层是数组Q且Vector有getҎ(gu)Q意味着它可能访问到q不属于最后一个位|元素的其他元素Q很不安全)(j)?
对于堆栈和队列只能用pushcdgetcR?
StackcM后不要轻易用?
Q!Q?a name="baidusnap1">实现堆栈一定要用LinkedList?


Q在JAVA1.5中,collection有queue来实现队列。)(j)










J2S 2007-03-19 22:04 发表评论
]]>
关于集合框架cȝ学习(fn)W记http://m.tkk7.com/bounce/archive/2007/03/19/104828.htmlJ2SJ2SMon, 19 Mar 2007 13:55:00 GMThttp://m.tkk7.com/bounce/archive/2007/03/19/104828.htmlhttp://m.tkk7.com/bounce/comments/104828.htmlhttp://m.tkk7.com/bounce/archive/2007/03/19/104828.html#Feedback0http://m.tkk7.com/bounce/comments/commentRss/104828.htmlhttp://m.tkk7.com/bounce/services/trackbacks/104828.html
集合cȝ对象是用来管理其他若q对象的Q它cM于C++标准模板库中的容器,不过在JAVA的集合类的对象中可以用来存放多种cd的对象?br />
接口和类共同构成?jin)一个集合框Ӟ集合的概念,一个对象可以装载多个对象,q个对象是集合对象?br />
集合框架

1Q接?br />
Collection 用来理多个对象Q集合中的每个元素都是对象?br />
MapQMap中没有对象,而是键值对Q由KeyQvaluel成的键值对QKey是不可重复的。value是可以相同的,一个Key和一个value一一对应?br />
集合中用到的c,接口在java.util包中Q在使用时注意将其引入import?br />
Collection 接口Q以下介l其子接口)(j)

1)List 一个List的实现类的对象在理多个对象时会(x)按顺序组l对象(x(chng)照将对象攑օ的顺序存储)(j)QList实现cȝ对象是由序的。(注意Q顺序和排序的区别)(j)

2)Set 一个Set的实现类表示一个数学概念上的集合,Set的实现类的对象中的元素是无顺序的Q也是不会(x)按照输入序来存?/font>QSet的实现类对象中的元素是不重复的?br />
3)SortedSet,他是Set的子接口Q他的实现类?x)对集合中的元素q行排序。但是要指定排序规则Q他?x)按排序规则q行排序?br />
Map 接口Q以下介l其子接口)(j)

SortedMapQ这个接口的实现cd样可以实玎ͼ不过是对键值对中的Keyq行排序Q这个接口的实现cM是要指定排序?br />则的?br />
JDK1.4中的集合是不安全的对象,JDK5.0中解决了(jin)q个问题?br />
List接口的实现类

1> ArrayList是接q于功能的集合类Q?font color="#ff0000">ArryList的实质就是一个会(x)自动增长的数l,ArrayList是用装的数l来实现的List接口的?/font>

Collection的实现类对象的遍历方式是用P代来实现的?br />在用P代器时先要活得一个P代器的对象,IteratorQP代器接口Q这是一个接口,q代器是在集合类中实现的Q也
是_(d)他是一个内部类Q匿名内部类Q实现的?br />Iterator接口中定义的常用Ҏ(gu)Ҏ(gu)hasNext()Qnext()?br />hasNext(),q个Ҏ(gu)?x)用一个游标,q过判断游标指向的位|是否存放有对象?br />next()Ҏ(gu)也是Iterator接口中定义好的方法,q个Ҏ(gu)?x)游标指向下一个元素的位置Q游标会(x)跌W一个元素,q?br />q回其中的内宏V?br />
Collections q是一个工L(fng)Q也是java.util包中的,q个cM的sort(list接口的实现类的对?Ҏ(gu)Q其参数是一个集合类的对象,q个Ҏ(gu)使用来对集合cȝ对象q行排序的。以后,我将以集合这个名字来U呼集合cȝ对象。,对于
字符串对象内容的集合来说?x)按字典序排序Q升序)(j)Q对于数字内容的集合排序也会(x)按照升序排序?br />
排序可一份ؓ(f)两部分内容,一个是排序的规则,也就是按照什么来q行排序Qƈ且排成什么样的顺序?br />W二个就是排序的法Q他军_?jin)排序的效率?br />
在对自定义的集合内容cd排序Ӟ需要先定义那个cd的排序规则?br />
Comparable接口Q这个接口中只定义了(jin)一个compareTo(Object o)Q方法的q回至类型是整型Q如果当前对象大于参数对象就q回正数Q当前对象等于参数对象是p?Q当前对象小于参数对象时p回负|q样写就是升序排列,反之则是q行降序排列Q?/font>在实现这个接口中的方法时Q返回值定义方式,只有q两U?br />
Ҏ(gu)指定cd的排序规则实C(jin)Comparable接口Q那么就可以对存有这个类型的集合q行整体排序。Comparable接口Q?br />也叫做可比较接口。这个接口在java.lang包下?font color="#ff0000">只要实现?jin)这个接口,是可排序?/font>?br />
接下来介l?font color="#008000">另外一U?/font>对自定义cd对象的集合整体排序的Ҏ(gu)Q?font color="#ff0000">也就是实现比较器接口QComparatorQ,q个接口中定义了(jin)一个compare(Object o1QObject o2)Ҏ(gu)来比较两个对象,q个Ҏ(gu)的返回值定义和上面介绍的那个方法是一栗?/font>

注意Q在APIQ帮助文档中以上两个Ҏ(gu)的参数类型是TQ这代表的模板类型,也就是集合中存放的内容的cdQ在JDK1.4中其参数是ObjectcdQ模板类型的详细内容?x)在最后的JDK5.0新特性中讲到?br />
Comparator接口可以在匿名内部类中实玎ͼCollections 中的sort(集合?jin)的对象Q比较器)Ҏ(gu)Q可以对自定义类型内容的集合q行整体排序?br />
2>LinkedListQ它是List接口的实现类Q?font style="BACKGROUND-COLOR: #ffffff" color="#ff0000">其底层是用双向@环链表来实现?/font>?br />
注意QArrayList的查询效率比较高Q增删动作的效率比较差,适用于查询比较频J,增删动作较少的元素管理的集合?
 (tng)  (tng)  (tng)LinkedList的查询效率低Q但是增删效率很高。适用于增删动作的比较频繁Q查询次数较?yu)的元素理集合?br />
ArrayListQ?font style="BACKGROUND-COLOR: #ffffff" color="#ff0000">LinkedList都是U程不安全的
?br />实现堆栈 1Q数l(ArrayListQ增删效率比较低Q不适合Q?br /> (tng)  (tng)  (tng)  (tng) 2Q?font color="#ff0000">LinkedListQ?font style="BACKGROUND-COLOR: #ffffff">实现堆栈的好Ҏ(gu)
Q?/font>
 (tng)  (tng)  (tng)  (tng) 3Qjava.util.Stackc,Stack是Vector的子c,VectorcL一个线E安全的Q是一个重量的类Q,q?br />?jin)Vector的方法,VerctorcdArrayList的功能近乎相同。(不推荐用StackcL实现堆栈Q?br />
Set接口的实现类

HashSet

Set的实现类的集合对象中不能够有重复元素QHashSet也一样他是用了(jin)一U标识来定元素的不重复QHashSet用一U算法来保证HashSet中的元素是不重复的,HashSet的底层实现还是数l?/font>?br />
ObjectcM的hashCode()的方法是所有子c都?x)承这个方?/font>Q这个方法会(x)用Hash法出一个HashQ哈希)(j)码D回,HashSet?x)用Hash码值去和数l长度取模,模(q个模就是对象要存放在数l中的位|)(j)相同时才?x)判断数l中的元素和要加入的对象的内Ҏ(gu)否相同,如果不同才会(x)dq去?br />
Hash法是一U散列算法?br />
注意Q?font color="#ff0000">所以要存入HashSet的集合对象中的自定义cd覆盖hashCode(),equals()两个Ҏ(gu)Q才能保证集合中元素容不重复
。在覆盖和hashCode()Ҏ(gu)Ӟ要相同对象的hashCode()Ҏ(gu)q回相同|覆盖equals()Ҏ(gu)再判断其内容。ؓ(f)?jin)保证效率,所以在覆盖hashCode()Ҏ(gu)Ӟ也要量使不同对象尽量返回不同的Hash码倹{?br />
如果数组中的元素和要加入的对象的hashCode()q回?jin)相同的Hash|相同对象Q?才会(x)用equals()Ҏ(gu)来判断两个对象的内容是否相同?br />
SortedSet接口是Set的子接口?br />TreeSet是SortedSet接口的实现类Q他可以寚w合中的元素进行排序?br />要存攑֜TreeSet中自定义cȝ对象Q这个类要么是已l实C(jin)Comparable接口Q要么是能给出Comparator比较器,TreeSet可以自动qo(h)掉重复元素所以不用重载hashCode()Ҏ(gu)QTreeSet?x)根据比较规则判断元素内?gu)否相同,TreeSet?x)在元素存入世就q行?jin)排序。(在TreeSetl出排序规则Ӟ一定要注意对象内容相等的条Ӟ一定要注意在主观的认ؓ(f)两个对象内容相同Ӟ才可以用比较少的条件来q行判断Q?br />
?font color="#ff0000">要排序时才用TreeSetc(存储效率比较低)(j)QHashSet的存储效率比较高
Q在需要ؓ(f)HashSet的对象排序时Q就可以把HashSet中的元素攑օTreeSet?br />

J2S 2007-03-19 21:55 发表评论
]]>
l于解脱?..http://m.tkk7.com/bounce/archive/2007/01/18/94738.htmlJ2SJ2SThu, 18 Jan 2007 11:56:00 GMThttp://m.tkk7.com/bounce/archive/2007/01/18/94738.htmlhttp://m.tkk7.com/bounce/comments/94738.htmlhttp://m.tkk7.com/bounce/archive/2007/01/18/94738.html#Feedback3http://m.tkk7.com/bounce/comments/commentRss/94738.htmlhttp://m.tkk7.com/bounce/services/trackbacks/94738.html
 (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)五天来^均每天也q?jin)不C时Q现在真有点不住了(jin)Q意识都模糊?jin)?j)Q但是ؓ(f)?jin)把生物钟调整过来,q是撑一?x)吧。突焉下来却不知道做点什么,20h个面试,{会(x)没事把Struts那本书再看看?br />
 (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)接下来都不知道写些什么东西,把实践中的一个弄明白的一个小知识C下:(x)
在JDBC中,对于游标对象ResultSet的getString()Ҏ(gu)也是用游标的模式来读取数据的Q不知道q样描叙对不对)(j)Q即Q你要取字段1Q字D?Q就必须先调用rs.getString(1)Q再调用rs.getString(2),不能反过来,否则不能正确d。原因还?sh)知道,有空了(jin)研I一下?img src ="http://m.tkk7.com/bounce/aggbug/94738.html" width = "1" height = "1" />

J2S 2007-01-18 19:56 发表评论
]]>
期末实践?.....http://m.tkk7.com/bounce/archive/2007/01/15/93840.htmlJ2SJ2SSun, 14 Jan 2007 18:41:00 GMThttp://m.tkk7.com/bounce/archive/2007/01/15/93840.htmlhttp://m.tkk7.com/bounce/comments/93840.htmlhttp://m.tkk7.com/bounce/archive/2007/01/15/93840.html#Feedback0http://m.tkk7.com/bounce/comments/commentRss/93840.htmlhttp://m.tkk7.com/bounce/services/trackbacks/93840.html今天成W都出来了(jin)Q结果还是比较理想的Q以后会(x)相对L些?br />
更新日志都是半个月前的事?jin),当时q说以后每天都更斎ͼ真是惭愧

q几天都是忙考试Q弄得心(j)力憔(zhn)_(d)今天晚上l于闲下来,l箋(hu)写实늚E序?br />
刚刚解决?jin)前几个时的困惑,现在对JAVA的内部类机制又有?jin)更新的认识Q兴奋中......Q,废话说Q来看代码:(x)

package tanzhang;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
import org.eclipse.swt.widgets.TabItem;
public class tanzhang {

 (tng)/**
 (tng) * Launch the application
 (tng) * @param args
 (tng) */
 (tng)private static Table table;
 (tng)private static TableItem newItemTableItem;

 (tng)
 (tng)public static void main(String[] args) {
 (tng) (tng)final Display display = Display.getDefault();
 (tng) (tng)final Shell shell = new Shell();
 (tng) (tng)shell.setImage(SWTResourceManager.getImage(tanzhang.class, "/org/eclipse/ui/internal/forms/widgets/progress.gif"));
 (tng) (tng)shell.setSize(774, 514);
 (tng) (tng)shell.setText("宣城供电(sh)局消弧U圈台帐");
............
............
............
 (tng) (tng)final Combo combo_1 = new Combo(composite, SWT.READ_ONLY);
 (tng) (tng)combo_1.addSelectionListener(new SelectionAdapter() {
 (tng) (tng) (tng)public void widgetSelected(SelectionEvent arg0) {
 (tng) (tng) (tng) (tng)String str=combo_1.getText();
 (tng) (tng) (tng) (tng)try{ (tng)
 (tng) (tng) (tng) (tng) (tng)String dbUrl = "jdbc:odbc:test";
 (tng) (tng) (tng) (tng) (tng)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 (tng) (tng) (tng) (tng) (tng)Connection conn = DriverManager.getConnection(dbUrl, "", "");
 (tng) (tng) (tng) (tng) (tng)Statement stmt=conn.createStatement();
 (tng) (tng) (tng) (tng) (tng)String sql="SELECT * from test where 单元名称="+str;
 (tng) (tng) (tng) (tng) (tng)ResultSet rs=stmt.executeQuery(sql);
 (tng) (tng) (tng) (tng) (tng)
 (tng) (tng) (tng) (tng) (tng)if(rs.next()){
 (tng) (tng) (tng) (tng) (tng)for(int i=0;i<=4;i++){ (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)
 (tng) (tng) (tng) (tng) (tng) (tng) (tng)newItemTableItem.setText(i,rs.getString(i+1)); (tng) (tng)
 (tng) (tng) (tng) (tng) (tng) (tng) (tng)}
 (tng) (tng) (tng) (tng) (tng)
 (tng) (tng) (tng) (tng) (tng)rs.close();
 (tng) (tng) (tng) (tng) (tng)stmt.close();
 (tng) (tng) (tng) (tng) (tng)conn.close();
 (tng) (tng) (tng) (tng) (tng)}
 (tng) (tng) (tng) (tng)}catch(Exception e){}
 (tng) (tng) (tng) (tng)
 (tng) (tng) (tng)}
 (tng) (tng)});
............
............
............

 (tng) (tng)table = new Table(composite_1, SWT.VIRTUAL | SWT.FULL_SELECTION | SWT.BORDER | SWT.HIDE_SELECTION);

 (tng) (tng)table.setLinesVisible(true);
 (tng) (tng)table.setHeaderVisible(true);
 (tng) (tng)table.setBounds(0, 0, 678, 80);
............
............
............

 (tng) (tng) (tng)刚开始是用final修饰table和newItemTableItemQ但是“newItemTableItem.setText(i,rs.getString(i+1));”这行(代码中兰色那句)(j)?x)报错,~译器提C“无法解析newItemTableItem”。我的第一反应是监听器的位|放得不寏V翻?jin)一下书Q说SWT/JFace事g代码中要讉KcM变量有三U方法:(x)Q?Q加finalQ(2Q将变量变(sh)ؓ(f)cȝ实例变量Q(3Q将事g代码写成命名内部c,然后通过构造函数的参数来传入?br /> (tng) (tng) (tng)想了(jin)惛_象只有第三种Ҏ(gu)值得试试Q但是后来想hnewItemTableItem是个对象Q传入以后却不知道怎么转换cdQ呆?..
 (tng) (tng) (tng)最后做?jin)个新的E序试了(jin)试,在新E序里是成功的,是要把newItemTableItem在main函数外申明其为private staticQ但是在旧的E序中,~译器是通过?jin),但是q行q接数据库查询的时候,出现“Fatal Exception...”的错误Q当时一下就蒙掉?jin)!Q完全一L(fng)Q怎么?x)不成功?br /> (tng) (tng) (tng)百般无奈以后Q?---当然之前肯定是深思熟?---l于脑v中闪Z(jin)传说中的“灵感”!于是马上把table也定义ؓ(f)private static......OKQ?tng) (tng) (tng)胜利L来得那么H然Q那瞬间的感觉就?0分钟打进的金?..

 (tng) (tng) (tng)当然到现在,我还没找到确切的原因。只能用自己的话ȝ一下:(x)Q?Q匿名内部类中的Ҏ(gu)是不能访问其他方法中定义的变量的Q包括实例对象)(j)Q要讉K必须在类中将其定义ؓ(f)staticcd。(2QTableItem是Table的子控gQ要定义TableItem为static也要同时把Table定义为staticcd?br />
 (tng) (tng) (tng)l自׃个Q务:(x)研究JAVA的内部类机制Q研ISWT中父子控件关pȝ机制Q?br />
 (tng) (tng) (tng)看看《Thinking in JAVA》或怼(x)是个不错的选择Q当然还有?a border="0">The Definitive Guide to SWT and JFace》?/p>

 (tng)



J2S 2007-01-15 02:41 发表评论
]]>
考完试了(jin)Q?/title><link>http://m.tkk7.com/bounce/archive/2007/01/01/91301.html</link><dc:creator>J2S</dc:creator><author>J2S</author><pubDate>Mon, 01 Jan 2007 08:42:00 GMT</pubDate><guid>http://m.tkk7.com/bounce/archive/2007/01/01/91301.html</guid><wfw:comment>http://m.tkk7.com/bounce/comments/91301.html</wfw:comment><comments>http://m.tkk7.com/bounce/archive/2007/01/01/91301.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/bounce/comments/commentRss/91301.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/bounce/services/trackbacks/91301.html</trackback:ping><description><![CDATA[昨天l于考完?jin)?br />都大四了(jin)Q还用最变态的老师Q三大魔_(d)(j)来折我们,对于q学校真无语?.....<br /><br />现在l于可以l箋(hu)我的自由学习(fn)之旅Q以后一定每天上来更新blog?br />旉不多?jin),既然已经饱受q往昏昏惑惑之疾、因循苟且之痛,那么现在p珍惜分分U秒QI补差距?br /><br />今天下午׃(jin)两个时把XML SPY教程学了(jin)一遍(没想到这么快能搞定)(j)Q我用的?007Q学的是2005Q但基本上没区别Q进度还是蛮快的。最后估计那个xml <font face="Helvetica">schema文g没写好,最后用xslt转换没成功。不q晚上准备再试一ơ,权当做复?fn)?br />以前都用C本写xmlQ现在用?jin)xml spy感觉真是太好用了(jin)Q尤其是xml数据与数据库的互相{换。而且q可以用工程来管理(q没试呢Q,对于开发大一点的E序无疑方便?jin)许多?br /><br />晚上再准备把struts那本书看看?br /><br />对了(jin)Q今天元旦,大家新q快乐,祷家h在新的一q里q_^安安Q?/font><img src ="http://m.tkk7.com/bounce/aggbug/91301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/bounce/" target="_blank">J2S</a> 2007-01-01 16:42 <a href="http://m.tkk7.com/bounce/archive/2007/01/01/91301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>12?9?/title><link>http://m.tkk7.com/bounce/archive/2006/12/19/88755.html</link><dc:creator>J2S</dc:creator><author>J2S</author><pubDate>Tue, 19 Dec 2006 05:05:00 GMT</pubDate><guid>http://m.tkk7.com/bounce/archive/2006/12/19/88755.html</guid><wfw:comment>http://m.tkk7.com/bounce/comments/88755.html</wfw:comment><comments>http://m.tkk7.com/bounce/archive/2006/12/19/88755.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/bounce/comments/commentRss/88755.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/bounce/services/trackbacks/88755.html</trackback:ping><description><![CDATA[ <p> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)昨天搞了(jin)一个下午加晚上Q配|eclipse3.2?qing)其插gQ最后太晚了(jin)没上来更新blog。有几点需要记一下:(x)<br /><br /> (tng) (tng) (tng) (tng) (tng) (tng)Q?Q其实在links目录里设|插件\径的时候?font color="#ff0000">//</font>”也是可以用的,|上一般说用?font color="#ff0000">/</font>”或?font color="#ff0000">\\</font>”。以后只要记住一点:(x)?font color="#0000ff">\</font>”(windows里的路径格式Q不能用p?jin)?br /><br /> (tng) (tng) (tng) (tng) (tng) (tng)Q?Qmyeclipse5.0以上必须配eclipse3.2Qmyeclipse4.0配eclipse3.0; 而myeclipse4.1才能配eclipse3.1?昨天刚开始没搞明白,l我的eclipse3.1.2下了(jin)一个myeclipse4.0和一个myeclipse5.1l果都不行,最后烦(ch)性下?jin)个最新的eclipse3.2.1Q心(j)惛_正早晚都要升U干脆现在提前搞定算?jin)?br /><br /> (tng) (tng) (tng) (tng) (tng) (tng)Q?Q关于eclipse3.2.1的lomboz插g问题Q在|上看了(jin)很多帖子Q其实源帖就两篇Q,ȝ如此Qa) all-in-one版本里其实已l包含了(jin)eclipse3.2?jin);b)<font color="#008000">两种选择</font>Q直接下?span lang="EN-US" style="COLOR: red">org.objectweb.lomboz-all-in-one-win32<font color="#000000">解压~即可;据说Z(jin)能支持GEF要分别下载这两个插g</font><font color="#ff0000">lomboz-S-3.2RC2-200608081203<font color="#000000">?/font>lomboz-and-prereqs-S-3.2RC2-200608081203</font><font color="#000000">q行安装。?我最后还是选择?jin)第二种?gu)?br /> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)其实有了(jin)myeclipseQlomboz可以不用装了(jin)Q我x(chng)只是Z(jin)多一U选择吧,不知道这是不是我骨子里已l开始們֐于开源了(jin)Q)(j)<br /><br /> (tng) (tng) (tng) (tng) (tng) (tng)Q?Q最后下?jin)一个javasript的eclipse插Ӟ但是安装不成功,不知道什么原因,反正以后再试?..<br /><br /><br /> (tng) (tng) (tng) (tng) (tng) (tng)最后,惌一点,其实昨天一天的工作是毫无技术含量的 Q而且现在旉q么紧,我应该把一些更重要或更有h(hun)值的事情提到议程之前来,而不是跟自己q不Lȝ角尖。我知道q是性格做怂,但是希望以后自己更理智点更“聪明”点。时间对于我们这L(fng)人是最宝贵的!</font></span></p> <img src ="http://m.tkk7.com/bounce/aggbug/88755.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/bounce/" target="_blank">J2S</a> 2006-12-19 13:05 <a href="http://m.tkk7.com/bounce/archive/2006/12/19/88755.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>初涉QJQhttp://m.tkk7.com/bounce/archive/2006/12/18/88402.htmlJ2SJ2SSun, 17 Dec 2006 16:32:00 GMThttp://m.tkk7.com/bounce/archive/2006/12/18/88402.htmlhttp://m.tkk7.com/bounce/comments/88402.htmlhttp://m.tkk7.com/bounce/archive/2006/12/18/88402.html#Feedback0http://m.tkk7.com/bounce/comments/commentRss/88402.htmlhttp://m.tkk7.com/bounce/services/trackbacks/88402.html多数 Web 应用E序都用请?响应模型从服务器上获得完整的 HTML 面。常常是点击一个按钮,{待服务器响应,再点d一个按钮,然后再等待,q样一个反复的q程。有?Ajax ?XMLHttpRequest 对象Q就可以使用不必让用L(fng)待服务器响应的请?响应模型?jin)。本文中QBrett McLaughlin 介绍?jin)如何创够适应不同览器的 XMLHttpRequest 实例Q徏立和发送请求,q响应服务器?/blockquote>

本系列的上一期文章(请参?参考资?/a> 中的链接Q,我们介绍?Ajax 应用E序Q考察?jin)推?Ajax 应用E序的基本概c(din)其中的核心(j)是很多?zhn)可能已经了(jin)解的技术:(x)JavaScript、HTML ?XHTML、一点动?HTML 以及(qing) DOMQ文档对象模型)(j)。本文将攑֤其中的一点,把目光放到具体的 Ajax l节上?/p>

本文中,(zhn)将开始接触最基本和基性的有关 Ajax 的全部对象和~程Ҏ(gu)QXMLHttpRequest 对象。该对象实际上仅仅是一个跨所?Ajax 应用E序的公qE,(zhn)可能已l预料到Q只有彻底理解该对象才能充分发挥~程的潜力。事实上Q有时?zhn)会(x)发玎ͼ要正地使?XMLHttpRequestQ显然不?使用 XMLHttpRequest。这到底是怎么回事呢?

Web 2.0 一?/a>

在深入研I代码之前首先看看最q的观点 —?一定要十分清楚 Web 2.0 q个概念。听?Web 2.0 q个词的时候,应该首先问一?“Web 1.0 是什么??虽然很少听h提到 Web 1.0Q实际上它指的就是具有完全不同的h和响应模型的传统 Web。比如,?Amazon.com |站上点M个按钮或者输入搜索项。就?x)对服务器发送一个请求,然后响应再返回到览器。该h不仅仅是图书和书目列表,而是另一个完整的 HTML 面。因此当 Web 览器用新的 HTML 面重绘Ӟ可能?x)看到闪烁或抖动。事实上Q通过看到的每个新面可以清晰地看到请求和响应?/p>

Web 2.0Q在很大E度上)(j)消除?jin)这U看得见的往复交互。比如访?Google Maps ?Flickr q样的站点(到这些支?Web 2.0 ?Ajax 站点的链接请参阅 参考资?/a>Q。比如在 Google Maps 上,(zhn)可以拖动地图,攑֤和羃?yu),只有很少的重l操作。当然这里仍然有h和响应,只不q都藏到?jin)幕后。作为用P体验更加舒适,感觉很像桌面应用E序。这U新的感受和范型是当有人提?Web 2.0 时?zhn)所体会(x)到的?/p>

需要关?j)的是如何ɘq些新的交互成ؓ(f)可能。显?dng)仍然需要发?gu)求和接收响应Q但正是针对每次h/响应交互?HTML 重绘造成?jin)缓慢、笨拙的 Web 交互的感受。因此很清楚Q我们需要一U方法发送的h和接收的响应?包含需要的数据而不是整?HTML 面。惟一需要获得整个新 HTML 面的时候就是希望用L(fng)?新页面的时候?/p>

但多C互都是在已有面上增加细节、修改主体文本或者覆盖原有数据。这些情况下QAjax ?Web 2.0 Ҏ(gu)允许在不 更新整个 HTML 面的情况下发送和接收数据。对于那些经怸|的人,q种能力可以让?zhn)的应用程序感觉更快、响应更?qing)时Q让他们不时地光?zhn)的网站?/p>





XMLHttpRequest ?/a>

要真正实现这U绚丽的奇迹Q必非常熟(zhn)一?JavaScript 对象Q即 XMLHttpRequest。这个小的对象实际上已l在几种览器中存在一D|间了(jin)Q它是本专栏今后几个月中要介l的 Web 2.0、Ajax 和大部分其他内容的核?j)。ؓ(f)?jin)让?zhn)快速地大体?jin)解它,下面l出要用于该对象的很少的几?Ҏ(gu)和属性?/p>

  • open()Q徏立到服务器的新请求?
  • send()Q向服务器发送请求?
  • abort()Q退出当前请求?
  • readyStateQ提供当?HTML 的就l状态?
  • responseTextQ服务器q回的请求响应文本?

如果不了(jin)解这些(或者其中的M 一个)(j)Q?zhn)也不用担心(j),后面几篇文章中我们将介绍每个?gu)和属性。现在应??jin)解的是Q明用 XMLHttpRequest 做什么。要注意q些Ҏ(gu)和属性都与发送请求及(qing)处理响应有关。事实上Q如果看?XMLHttpRequest 的所有方法和属性,׃(x)发现它们?与非常简单的h/响应模型有关。显?dng)我们不?x)遇到特别新的 GUI 对象或者创建用户交互的某种极秘的方法,我们用非常简单的h和非常简单的响应。听hg没有多少吸引力,但是用好该对象可以彻底改变?zhn)的应用程序?/p>

单的 new

首先需要创Z个新变量q赋l它一?XMLHttpRequest 对象实例。这?JavaScript 中很单,只要对该对象名?new 关键字即可,?清单 1 所C?/p>

清单 1. 创徏新的 XMLHttpRequest 对象
<script language="javascript" type="text/javascript">
                        var request = new XMLHttpRequest();
                        </script>
                        

不难吧?CQJavaScript 不要求指定变量类型,因此不需要像 清单 2 那样做(?Java 语言中可能需要这P(j)?/p>

清单 2. 创徏 XMLHttpRequest ?Java 伪代?/a>
XMLHttpRequest request = new XMLHttpRequest();
                        

因此?JavaScript 中用 var 创徏一个变量,l它一个名字(?“request”)(j)Q然后赋l它一个新?XMLHttpRequest 实例。此后就可以在函C使用该对象了(jin)?/p>

错误处理

在实际上各种事情都可能出错,而上面的代码没有提供M错误处理。较好的办法是创对象Qƈ在出现问题时优雅地退出。比如,M较早的浏览器Q不论?zhn)是否怿Q仍然有人在使用老版本的 Netscape NavigatorQ都不支?XMLHttpRequestQ?zhn)需要让q些用户知道有些地方Z(jin)问题?a >清单 3 说明如何创徏该对象,以便在出现问题的时候发?JavaScript 警告?/p>

清单 3. 创徏h错误处理能力?XMLHttpRequest
<script language="javascript" type="text/javascript">
                        var request = false;
                        try {
                        request = new XMLHttpRequest();
                        } catch (failed) {
                        request = false;
                        }
                        if (!request)
                        alert("Error initializing XMLHttpRequest!");
                        </script>
                        

一定要理解q些步骤Q?/p>

  1. 创徏一个新变量 request q赋?false。后面将使用 false 作ؓ(f)判定条gQ它表示q没有创?XMLHttpRequest 对象?
  2. 增加 try/catch 块:(x)
    1. 试创徏 XMLHttpRequest 对象?
    2. 如果p|Qcatch (failed)Q则保证 request 的g然ؓ(f) false?
  3. (g)?request 是否仍ؓ(f) falseQ如果一切正常就不会(x)?falseQ?
  4. 如果出现问题Qrequest ?falseQ则使用 JavaScript 警告通知用户出现?jin)问题?

代码非常单,对大多数 JavaScript ?Web 开发h员来_(d)真正理解它要比读写代码花更长的时间。现在已l得C(jin)一D带有错误检查的 XMLHttpRequest 对象创徏代码Q还可以告诉(zhn)哪儿出?jin)问题?/p>

应付 Microsoft

看v来似乎一切良好,臛_在用 Internet Explorer 试验q些代码之前是这L(fng)。如果这栯验的话,׃(x)看到 ?1 所C的p糕情Ş?/p>

?1. Internet Explorer 报告错误
Internet Explorer 报告错误
Microsoft 参与?jin)吗Q?/a>
关于 Ajax ?Microsoft 对该领域不断增长的兴和参与已经有很多文章进行了(jin)介绍。事实上Q据?Microsoft 最新版本的 Internet Explorer —?version 7.0Q将?2006 q下半年推出 —?开始直接支?XMLHttpRequestQ让(zhn)?new 关键字代替所有的 Msxml2.XMLHTTP 创徏代码。但不要太激动,仍然需要支持旧的浏览器Q因此跨览器代码不?x)很快消失?

昄有什么地方不对劲Q?Internet Explorer 很难说是一U过时的览器,因ؓ(f)全世界有 70% 在?Internet Explorer。换句话_(d)如果不支?Microsoft ?Internet Explorer ׃?x)受?Web 世界的欢q!因此我们需要采用不同的Ҏ(gu)处理 Microsoft 览器?/p>

l验证发?Microsoft 支持 AjaxQ但是其 XMLHttpRequest 版本有不同的U呼。事实上Q它?yu)其UCؓ(f)几种 不同的东ѝ如果用较新版本的 Internet ExplorerQ则需要用对?Msxml2.XMLHTTPQ而较老版本的 Internet Explorer 则?Microsoft.XMLHTTP。我们需要支持这两种对象cdQ同时还要支持非 Microsoft 览器)(j)。请看看 清单 4Q它在前qC码的基础上增加了(jin)?Microsoft 的支持?/p>

清单 4. 增加?Microsoft 览器的支持
<script language="javascript" type="text/javascript">
                        var request = false;
                        try {
                        request = new XMLHttpRequest();
                        } catch (trymicrosoft) {
                        try {
                        request = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (othermicrosoft) {
                        try {
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (failed) {
                        request = false;
                        }
                        }
                        }
                        if (!request)
                        alert("Error initializing XMLHttpRequest!");
                        </script>
                        

很容易被q些花括可住了(jin)眼睛Q因此下面分别介l每一步:(x)

  1. 创徏一个新变量 request q赋?false。?false 作ؓ(f)判断条gQ它表示q没有创?XMLHttpRequest 对象?
  2. 增加 try/catch 块:(x)
    1. 试创徏 XMLHttpRequest 对象?
    2. 如果p|Qcatch (trymicrosoft)Q:(x)
      1. 试使用较新版本?Microsoft 览器创?Microsoft 兼容的对象(Msxml2.XMLHTTPQ?
      2. 如果p|Qcatch (othermicrosoft)Q尝试用较老版本的 Microsoft 览器创?Microsoft 兼容的对象(Microsoft.XMLHTTPQ?
    3. 如果p|Qcatch (failed)Q则保证 request 的g然ؓ(f) false?
  3. (g)?request 是否仍然?falseQ如果一切顺利就不会(x)?falseQ?
  4. 如果出现问题Qrequest ?falseQ则使用 JavaScript 警告通知用户出现?jin)问题?

q样修改代码之后再?Internet Explorer 试验Q就应该看到已经创徏的表单(没有错误消息Q。我实验的结果如 ?2 所C?/p>

?2. Internet Explorer 正常工作
Internet Explorer 正常工作

?rn)态与动?/a>

再看一看清?1?a >3 ?4Q注意,所有这些代码都直接嵌套?script 标记中。像q种不放到方法或函数体中?JavaScript 代码UCؓ(f)?rn)?JavaScript。就是说代码是在面昄l用户之前的某个时候运行。(虽然Ҏ(gu)规范不能完全_?知道q些代码何时q行Ҏ(gu)览器有什么媄(jing)响,但是可以保证q些代码在用戯够与面交互之前q行。)(j)q也是多?Ajax E序员创?XMLHttpRequest 对象的一般方式?/p>

是_(d)也可以像 清单 5 那样这些代码放在一个方法中?/p>

清单 5. ?XMLHttpRequest 创徏代码Ud到方法中
<script language="javascript" type="text/javascript">
                        var request;
                        function createRequest() {
                        try {
                        request = new XMLHttpRequest();
                        } catch (trymicrosoft) {
                        try {
                        request = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (othermicrosoft) {
                        try {
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (failed) {
                        request = false;
                        }
                        }
                        }
                        if (!request)
                        alert("Error initializing XMLHttpRequest!");
                        }
                        </script>
                        

如果按照q种方式~写代码Q那么在处理 Ajax 之前需要调用该Ҏ(gu)。因此还需?清单 6 q样的代码?/p>

清单 6. 使用 XMLHttpRequest 的创建方?/a>
<script language="javascript" type="text/javascript">
                        var request;
                        function createRequest() {
                        try {
                        request = new XMLHttpRequest();
                        } catch (trymicrosoft) {
                        try {
                        request = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (othermicrosoft) {
                        try {
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (failed) {
                        request = false;
                        }
                        }
                        }
                        if (!request)
                        alert("Error initializing XMLHttpRequest!");
                        }
                        function getCustomerInfo() {
                        createRequest();
                        // Do something with the request variable
                        }
                        </script>
                        

此代码惟一的问题是推迟?jin)错误通知Q这也是多数 Ajax E序员(sh)采用q一Ҏ(gu)的原因。假设一个复杂的表单?10 ?15 个字Dc(din)选择框等Q当用户在第 14 个字D(按照表单序从上CQ输入文本时要激zL?Ajax 代码。这时候运?getCustomerInfo() 试创徏一?XMLHttpRequest 对象Q但Q对于本例来_(d)(j)p|?jin)。然后向用户昄一条警告,明确地告诉他们不能用该应用E序。但用户已经p?jin)很多时间在表单中输入数据!q是非常令h讨厌的,而讨厌显然不?x)吸引用户再ơ访问(zhn)的网站?/p>

如果使用?rn)?JavaScriptQ用户在点击面的时候很快就?x)看到错误信息。这样也很烦(ch)人,是不是?可能令用户错误地认ؓ(f)(zhn)的 Web 应用E序不能在他的浏览器上运行。不q,当然要比他们p?10 分钟输入信息之后再显C同L(fng)错误要好。因此,我徏议编写静(rn)态的代码Q让用户可能早地发现问题?/p>





?XMLHttpRequest 发送请?/a>

得到h对象之后可以进入请?响应循环?jin)。记住,XMLHttpRequest 惟一的目的是让?zhn)发送请求和接收响应。其他一切都?JavaScript、CSS 或页面中其他代码的工作:(x)改变用户界面、切换图像、解释服务器q回的数据。准备好 XMLHttpRequest 之后Q就可以向服务器发送请求了(jin)?/p>

Ƣ迎使用沙箱

Ajax 采用一U沙安全模型。因此,Ajax 代码Q具体来说就?XMLHttpRequest 对象Q只能对所在的同一个域发送请求。以后的文章中将q一步介l安全和 AjaxQ现在只要知道在本地机器上运行的代码只能Ҏ(gu)地机器上的服务器端脚本发送请求。如果让 Ajax 代码?www.breakneckpizza.com 上运行,则必?www.breakneck.com 中运行的脚本发送请求?/p>

讄服务?URL

首先要确定连接的服务器的 URL。这q不?Ajax 的特D要求,但仍然是建立q接所必需的,昄现在(zhn)应该知道如何构?URL ?jin)。多数应用程序中都会(x)l合一些静(rn)态数据和用户处理的表单中的数据来构造该 URL。比如,清单 7 中的 JavaScript 代码获取?sh)话L(fng)字段的值ƈ用其构?URL?/p>

清单 7. 建立h URL
<script language="javascript" type="text/javascript">
                        var request = false;
                        try {
                        request = new XMLHttpRequest();
                        } catch (trymicrosoft) {
                        try {
                        request = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (othermicrosoft) {
                        try {
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (failed) {
                        request = false;
                        }
                        }
                        }
                        if (!request)
                        alert("Error initializing XMLHttpRequest!");
                        function getCustomerInfo() {
                        var phone = document.getElementById("phone").value;
                        var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
                        }
                        </script>
                        

q里没有难懂的地斏V首先,代码创徏?jin)一个新变量 phoneQƈ?ID ?“phone?的表单字D늚Dl它?a >清单 8 展示?jin)这个表单?XHTMLQ其中可以看?phone 字段?qing)?id 属性?/p>

清单 8. Break Neck Pizza 表单
 <body>
                        <p><img src="breakneck-logo_4c.gif" alt="Break Neck Pizza" /></p>
                        <form action="POST">
                        <p>Enter your phone number:
                        <input type="text" size="14" name="phone" id="phone"
                        onChange="getCustomerInfo();" />
                        </p>
                        <p>Your order will be delivered to:</p>
                        <div id="address"></div>
                        <p>Type your order in here:</p>
                        <p><textarea name="order" rows="6" cols="50" id="order"></textarea></p>
                        <p><input type="submit" value="Order Pizza" id="submit" /></p>
                        </form>
                        </body>
                        

q要注意Q当用户输入?sh)话L(fng)或者改变电(sh)话号码时Q将触发 清单 8 所C的 getCustomerInfo() Ҏ(gu)。该Ҏ(gu)取得?sh)话L(fng)q构造存储在 url 变量中的 URL 字符丌Ӏ记住,׃ Ajax 代码是沙型的,因而只能连接到同一个域Q实际上 URL 中不需要域名。该例中的脚本名?/cgi-local/lookupCustomer.php。最后,?sh)话L(fng)作ؓ(f) GET 参数附加到该脚本中:(x)"phone=" + escape(phone)?/p>

如果以前没用见过 escape() Ҏ(gu)Q它用于转义不能用明文正发送的M字符。比如,?sh)话L(fng)中的I格被转换成字W?%20Q从而能够在 URL 中传递这些字W?/p>

可以Ҏ(gu)需要添加Q意多个参数。比如,如果需要增加另一个参敎ͼ只需要将光加到 URL 中ƈ?“与”(&Q字W分开 [W一个参数用问号Q?Q和脚本名分开]?/p>

打开h

open() 是打开吗?
Internet 开发h员对 open() Ҏ(gu)到底做什么没有达成一致。但它实际上q不?打开一个请求。如果监?XHTML/Ajax 面?qing)其q接脚本之间的网l和数据传递,当调?open() Ҏ(gu)时将看不CQ何通信。不清楚Z选用?jin)这个名字,但显然不是一个好的选择?

有了(jin)要连接的 URL 后就可以配置h?jin)。可以用 XMLHttpRequest 对象?open() Ҏ(gu)来完成。该Ҏ(gu)有五个参敎ͼ(x)

  • request-typeQ发送请求的cd。典型的值是 GET ?POSTQ但也可以发?HEAD h?
  • urlQ要q接?URL?
  • asynchQ如果希望用异步连接则?trueQ否则ؓ(f) false。该参数是可选的Q默认ؓ(f) true?
  • usernameQ如果需要n份验证,则可以在此指定用户名。该可选参数没有默认倹{?
  • passwordQ如果需要n份验证,则可以在此指定口令。该可选参数没有默认倹{?

通常使用其中的前三个参数。事实上Q即佉K要异步连接,也应该指定第三个参数?“true”。这是默认|但坚持明指定请求是异步的还是同步的更容易理解?/p>

这些结合v来,通常?x)得?清单 9 所C的一行代码?/p>

清单 9. 打开h
   function getCustomerInfo() {
                        var phone = document.getElementById("phone").value;
                        var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
                        request.open("GET", url, true);
                        }
                        

一旦设|好?URLQ其他就单了(jin)。多数请求?GET 够?jin)(后面的文章中看到需要?POST 的情况)(j)Q再加上 URLQ这是使用 open() Ҏ(gu)需要的全部内容?jin)?/p>

?xi)战异步?/a>

本系列的后面一文章中Q我用很多旉~写和用异步代码,但是(zhn)应该明白ؓ(f)什?open() 的最后一个参数这么重要。在一般的h/响应模型中,比如 Web 1.0Q客hQ浏览器或者本地机器上q行的代码)(j)向服务器发出h。该h是同步的Q换句话_(d)客户机等待服务器的响应。当客户机等待的时候,臛_?x)用某种形式通知(zhn)在{待Q?/p>

  • 沙漏Q特别是 Windows 上)(j)?
  • 旋{的皮球(通常?Mac 机器上)(j)?
  • 应用E序基本上冻l了(jin)Q然后过一D|间光标变化了(jin)?

q正?Web 应用E序让h感到W拙或缓慢的原因 —?~Z真正的交互性。按下按钮时Q应用程序实际上变得不能使用Q直到刚刚触发的h得到响应。如果请求需要大量服务器处理Q那么等待的旉可能很长Q至在q个多处理器、DSL 没有{待的世界中是如此)(j)?/p>

而异步请求不 {待服务器响应。发送请求后应用E序l箋(hu)q行。用户仍然可以在 Web 表单中输入数据,甚至d表单。没有旋转的皮球或者沙漏,应用E序也没有明昄ȝ。服务器(zhn)?zhn)地响应请求,完成后告诉原来的h者工作已l结束(具体的办法很快就?x)看刎ͼ?j)。结果是Q应用程序感觉不 那么q钝或者缓慢,而是响应q速、交互性强Q感觉快多了(jin)。这仅仅?Web 2.0 的一部分Q但它是很重要的一部分。所有老套?GUI lg?Web 设计范型都不能克服缓慢、同步的h/响应模型?/p>

发送请?/a>

一旦用 open() 配置好之后,可以发送请求了(jin)。幸q的是,发送请求的Ҏ(gu)的名U要?open() 适当Q它?yu)?send()?/p>

send() 只有一个参敎ͼ是要发送的内容。但是在考虑q个Ҏ(gu)之前Q回想一下前面已l通过 URL 本n发送过数据?jin)?x)

var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
                        

虽然可以使用 send() 发送数据,但也能通过 URL 本n发送数据。事实上QGET hQ在典型?Ajax 应用中大U占 80%Q中Q用 URL 发送数据要Ҏ(gu)得多。如果需要发送安全信息或 XMLQ可能要考虑使用 send() 发送内容(本系列的后箋(hu)文章中将讨论安全数据?XML 消息Q。如果不需要通过 send() 传递数据,则只要传?null 作ؓ(f)该方法的参数卛_。因此?zhn)会(x)发现在本文中的例子中只需要这样发送请求(参见 清单 10Q?/p>

清单 10. 发送请?/a>
   function getCustomerInfo() {
                        var phone = document.getElementById("phone").value;
                        var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
                        request.open("GET", url, true);
                        request.send(null);
                        }
                        

指定回调Ҏ(gu)

现在我们所做的只有很少一Ҏ(gu)新的、革命性的或异步的。必L认,open() Ҏ(gu)?“true?q个小的关键字建立?jin)异步请求。但是除此之外,q些代码与用 Java servlet ?JSP、PHP ?Perl ~程没有什么两栗那?Ajax ?Web 2.0 最大的U密是什么呢Q秘密就在于 XMLHttpRequest 的一个简单属?onreadystatechange?/p>

首先一定要理解q些代码中的程Q如果需要请回顾 清单 10Q。徏立其h然后发出h。此外,因ؓ(f)是异步请求,所?JavaScript Ҏ(gu)Q例子中?getCustomerInfo()Q不?x)等待服务器。因此代码将l箋(hu)执行Q就是说Q将退?gu)?gu)而把控制q回l表单。用户可以l输入信息,应用E序不会(x){待服务器?/p>

q就提出?jin)一个有的问题Q服务器完成?jin)请求之后?x)发生什么?{案是什么也不发生,臛_对现在的代码而言如此Q显然这样不行,因此服务器在完成通过 XMLHttpRequest 发送给它的h处理之后需要某U指C明怎么做?/p>
?JavaScript 中引用函?/a>
JavaScript 是一U弱cd的语aQ可以用变量引用M东西。因此如果声明了(jin)一个函?updatePage()QJavaScript 也将该函数名看作是一个变量。换句话_(d)可用变量?updatePage 在代码中引用函数?

现在 onreadystatechange 属性该d?jin)。该属性允许指定一个回调函数。回调允许服务器Q猜得到吗?Q反向调?Web 面中的代码。它也给?jin)服务器一定程度的控制权,当服务器完成h之后Q会(x)查看 XMLHttpRequest 对象Q特别是 onreadystatechange 属性。然后调用该属性指定的MҎ(gu)。之所以称为回调是因ؓ(f)服务器向|页发v调用Q无论网|w在做什么。比方说Q可能在用户坐在椅子上手没有键盘的时候调用该Ҏ(gu)Q但是也可能在用戯入、移动鼠标、滚动屏q或者点?yn)L钮时调用该方法。它q不兛_(j)用户在做什么?/p>

q就是称之ؓ(f)异步的原因:(x)用户在一层上操作表单Q而在另一层上服务器响应请求ƈ触发 onreadystatechange 属性指定的回调Ҏ(gu)。因此需要像 清单 11 一样在代码中指定该Ҏ(gu)?/p>

清单 11. 讄回调Ҏ(gu)
   function getCustomerInfo() {
                        var phone = document.getElementById("phone").value;
                        var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
                        request.open("GET", url, true);
                        request.onreadystatechange = updatePage;
                        request.send(null);
                        }
                        

需要特别注意的是该属性在代码中设|的位置 —?它是在调?send() 之前 讄的。发送请求之前必设|该属性,q样服务器在回答完成h之后才能查看该属性。现在剩下的只有编?updatePage() Ҏ(gu)?jin),q是本文最后一节要讨论的重炏V?/p>





处理服务器响?/a>

发送请求,用户高兴C?Web 表单Q同时服务器在处理请求)(j)Q而现在服务器完成?jin)请求处理。服务器查看 onreadystatechange 属性确定要调用的方法。除此以外,可以?zhn)的应用程序看作其他应用程序一P无论是否异步。换句话_(d)不一定要采取Ҏ(gu)的动作编写响应服务器的方法,只需要改变表单,让用戯问另一?URL 或者做响应服务器需要的M事情。这一节我们重点讨论对服务器的响应和一U典型的动作 —?x(chng)改变用户看到的表单中的一部分?/p>

回调?Ajax

现在我们已经看到如何告诉服务器完成后应该做什么:(x)?XMLHttpRequest 对象?onreadystatechange 属性设|ؓ(f)要运行的函数名。这P当服务器处理完请求后׃(x)自动调用该函数。也不需要担?j)该函数的Q何参数。我们从一个简单的Ҏ(gu)开始,?清单 12 所C?/p>

清单 12. 回调Ҏ(gu)的代?/a>
<script language="javascript" type="text/javascript">
                        var request = false;
                        try {
                        request = new XMLHttpRequest();
                        } catch (trymicrosoft) {
                        try {
                        request = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (othermicrosoft) {
                        try {
                        request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (failed) {
                        request = false;
                        }
                        }
                        }
                        if (!request)
                        alert("Error initializing XMLHttpRequest!");
                        function getCustomerInfo() {
                        var phone = document.getElementById("phone").value;
                        var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
                        request.open("GET", url, true);
                        request.onreadystatechange = updatePage;
                        request.send(null);
                        }
                        function updatePage() {
                        alert("Server is done!");
                        }
                        </script>
                        

它仅仅发Z些简单的警告Q告诉?zhn)服务器什么时候完成了(jin)d。在自己的网中试验q些代码Q然后在览器中打开Q如果希望查看该例中?XHTMLQ请参阅 清单 8Q。输入电(sh)话号码然后离开该字D,看C个弹出的警告H口Q如 ?3 所C)(j)Q但是点?OK 又出C(jin)…?/p>

?3. 弹出警告?Ajax 代码
弹出警告?Ajax 代码

Ҏ(gu)?hu)览器的不同Q在表单停止弹出警告之前?x)看Cơ、三ơ甚臛_ơ警告。这是怎么回事呢?原来我们q没有考虑 HTTP qA状态,q是h/响应循环中的一个重要部分?/p>

HTTP qA状?/a>

前面提到Q服务器在完成请求之后会(x)?XMLHttpRequest ?onreadystatechange 属性中查找要调用的Ҏ(gu)。这是真的,但还?sh)完整。事实上Q每?HTTP qA状态改变时它都?x)调用该?gu)。这意味着什么呢Q首先必ȝ?HTTP qA状态?/p>

HTTP qA状态表C求的状态或情Ş。它用于定该请求是否已l开始、是否得C(jin)响应或者请?响应模型是否已经完成。它q可以帮助确定读取服务器提供的响应文本或数据是否安全。在 Ajax 应用E序中需要了(jin)解五U就l状态:(x)

  • 0Q请求没有发出(在调?open() 之前Q?
  • 1Q请求已l徏立但q没有发出(调用 send() 之前Q?
  • 2Q请求已l发出正在处理之中(q里通常可以从响应得到内容头部)(j)?
  • 3Q请求已l处理,响应中通常有部分数据可用,但是服务器还没有完成响应?
  • 4Q响应已完成Q可以访问服务器响应q用它?

与大多数跨浏览器问题?sh)Pq些qA状态的使用也不一致。?zhn)也许期望dqA状态从 0 ?1?? 再到 4Q但实际上很是q种情况。一些浏览器从不报告 0 ?1 而直接从 2 开始,然后?3 ?4。其他浏览器则报告所有的状态。还有一些则多次报告qA状?1。在上一节中看到Q服务器多次调用 updatePage()Q每ơ调用都?x)弹(gu)告?—?可能和预期的不同Q?/p>

对于 Ajax ~程Q需要直接处理的惟一状态就是就l状?4Q它表示服务器响应已l完成,可以安全C用响应数据了(jin)。基于此Q回调方法中的第一行应该如 清单 13 所C?/p>

清单 13. (g)查就l状?/a>
   function updatePage() {
                        if (request.readyState == 4)
                        alert("Server is done!");
                        }
                        

修改后就可以保证服务器的处理已经完成。尝试运行新版本?Ajax 代码Q现在就?x)看C预期的一P只显CZơ警告信息了(jin)?/p>

HTTP 状态码

虽然 清单 13 中的代码看v来似乎不错,但是q有一个问?—?如果服务器响应请求ƈ完成?jin)处理但是报告?jin)一个错误怎么办?要知道,服务器端代码应该明白它是?Ajax、JSP、普?HTML 表单或其他类型的代码调用的,但只能用传l的 Web 专用Ҏ(gu)报告信息。而在 Web 世界中,HTTP 代码可以处理h中可能发生的各种问题?/p>

比方_(d)(zhn)肯定遇到过输入?jin)错误?URL h而得?404 错误码的情ŞQ它表示该页面不存在。这仅仅?HTTP h能够收到的众多错误码中的一U(完整的状态码列表请参?参考资?/a> 中的链接Q。表C所讉K数据受到保护或者禁止访问的 403 ?401 也很常见。无论哪U情况,q些错误码都是从完成的响?得到的。换句话_(d)服务器行了(jin)hQ即 HTTP qA状态是 4Q但是没有返回客h预期的数据?/p>

因此除了(jin)qA状态外Q还需要检?HTTP 状态。我们期望的状态码?200Q它表示一切顺利。如果就l状态是 4 而且状态码?200Q就可以处理服务器的数据?jin),而且q些数据应该是要求的数据(而不是错误或者其他有问题的信息)(j)。因此还要在回调Ҏ(gu)中增加状态检查,?清单 14 所C?/p>

清单 14. (g)?HTTP 状态码
   function updatePage() {
                        if (request.readyState == 4)
                        if (request.status == 200)
                        alert("Server is done!");
                        }
                        

Z(jin)增加更健壮的错误处理q尽量避免过于复杂,可以增加一两个状态码(g)查,L(fng)一?清单 15 中修改后?updatePage() 版本?/p>

清单 15. 增加一炚w误检?/a>
   function updatePage() {
                        if (request.readyState == 4)
                        if (request.status == 200)
                        alert("Server is done!");
                        else if (request.status == 404)
                        alert("Request URL does not exist");
                        else
                        alert("Error: status code is " + request.status);
                        }
                        

现在?getCustomerInfo() 中的 URL 改ؓ(f)不存在的 URL 看看?x)发生什么。应该会(x)看到警告信息说明要求?URL 不存?—?好极?jin)!很难处理所有的错误条gQ但是这一小的改变能够涵盖典?Web 应用E序?80% 的问题?/p>

d响应文本

现在可以保h已经处理完成Q通过qA状态)(j)Q服务器l出?jin)正常的响应Q通过状态码Q,最后我们可以处理服务器q回的数据了(jin)。返回的数据保存?XMLHttpRequest 对象?responseText 属性中?/p>

关于 responseText 中的文本内容Q比如格式和长度Q有意保持含p。这h务器可以将文本讄成Q何内宏V比方说Q一U脚本可能返回逗号分隔的|另一U则使用道W(?| 字符Q分隔的|q有一U则q回长文本字W串。何M从由服务器决定?/p>

在本文用的例子中,服务器返回客L(fng)上一个订单和客户地址Q中间用道W分开。然后用订单和地址讄表单中的元素|清单 16 l出?jin)更新显C内容的代码?/p>

清单 16. 处理服务器响?/a>
   function updatePage() {
                        if (request.readyState == 4) {
                        if (request.status == 200) {
                        var response = request.responseText.split("|");
                        document.getElementById("order").value = response[0];
                        document.getElementById("address").innerHTML =
                        response[1].replace(/\n/g, "
"); } else alert("status is " + request.status); } }

首先Q得?responseText q?JavaScript split() Ҏ(gu)从管道符分开。得到的数组攑ֈ response 中。数l中的第一个?—?上一个订?—??response[0] 讉KQ被讄?ID ?“order?的字D늚倹{第二个?response[1]Q即客户地址Q则需要更多一点处理。因为地址中的行用一般的行分隔符Q“\n”字W)(j)分隔Q代码中需要用 XHTML 风格的行分隔W?<br /> 来代ѝ替换过E?replace() 函数和正则表辑ּ完成。最后,修改后的文本作ؓ(f) HTML 表单 div 中的内部 HTML。结果就是表单突然用客户信息更新?jin),如?4 所C?/p>

?4. 收到客户数据后的 Break Neck 表单
收到客户数据后的 Break Neck 表单

l束本文之前Q我q要介绍 XMLHttpRequest 的另一个重要属?responseXML。如果服务器选择使用 XML 响应则该属性包含(也许(zhn)已l猜刎ͼ(j)XML 响应。处?XML 响应和处理普通文本有很大不同Q涉?qing)到解析、文档对象模型(DOMQ和其他一些问题。后面的文章中将q一步介l?XML。但是因?responseXML 通常?responseText 一赯论,q里有必要提一提。对于很多简单的 Ajax 应用E序 responseText 够?jin),但是?zhn)很快就?x)看到通过 Ajax 应用E序也能很好地处?XML?/p>





l束?/a>

(zhn)可能对 XMLHttpRequest 感到有点厌倦了(jin)Q我很少看到一整篇文章讨论一个对象,特别是这U简单的对象。但是?zhn)在使?Ajax ~写的每个页面和应用E序中反复用该对象。坦白地_(d)关于 XMLHttpRequest q真有一些可说的内容。下一期文章中介l如何在h中?POST ?GETQ来讄h中的内容头部和从服务器响应读取内容头部,理解如何在请?响应模型中编码请求和处理 XML?/p>

再往后我们将介绍常见 Ajax 工具。这些工L(fng)实际上隐藏了(jin)本文所q的很多l节Q?Ajax ~程更容易。?zhn)也许会(x)想Q既然有q么多工L(fng)Zq要对底层的l节~码。答案是Q如果不知道应用E序在做什么,很隑֏现应用程序中的问题?/p>

因此不要忽略q些l节或者简单地览一下,如果便捷华丽的工L(fng)出现?jin)错误,?zhn)就不必挠头或者发送邮件请求支持了(jin)。如果了(jin)解如何直接?XMLHttpRequestQ就?x)发现很?gu)调试和解x(chng)奇怪的问题。只有让其解x(chng)的问题,工具才是好东西?/p>

因此L(fng)(zhn)?XMLHttpRequest 吧。事实上Q如果?zhn)有用工L(fng)?Ajax 代码Q可以尝试?XMLHttpRequest 对象?qing)其属性和Ҏ(gu)重新改写。这是一U不错的l习(fn)Q可以帮助?zhn)更好地理解其中的原理?/p>

J2S 2006-12-18 00:32 发表评论
]]>
SWT/JFace开发入门指南(十一Q〈{帖?/title><link>http://m.tkk7.com/bounce/archive/2006/12/18/88401.html</link><dc:creator>J2S</dc:creator><author>J2S</author><pubDate>Sun, 17 Dec 2006 16:26:00 GMT</pubDate><guid>http://m.tkk7.com/bounce/archive/2006/12/18/88401.html</guid><wfw:comment>http://m.tkk7.com/bounce/comments/88401.html</wfw:comment><comments>http://m.tkk7.com/bounce/archive/2006/12/18/88401.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/bounce/comments/commentRss/88401.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/bounce/services/trackbacks/88401.html</trackback:ping><description><![CDATA[ <h1 style="MARGIN: 11pt 0cm"> <span> <font size="3"> <font style="BACKGROUND-COLOR: #e5e5e5">JFace中的工具条和菜单 <p></p></font> </font> </span> </h1> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">前一节中我们单介l了(jin)一?/span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是一个最常用的事Ӟ举个例子来说Q对于一个按钮来说它可以有多个事Ӟ比如按键Q焦点,鼠标Q等{等{吧Q但是实际上在用程序的时候,我们最兛_(j)的,是按下去这个按钮会(x)发生什么,q个其实是所谓的</span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。如果大家以前做q?/span> <span lang="EN-US">swing/awt</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">变成的话Q应该对</span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不会(x)陌生?/span> </font> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">里面Q一?/span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对象Q这些对象就是所谓的</span> <span lang="EN-US">Contribution Item</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。比如我们在一般程序里面很常见的“文件”菜单,下面都会(x)有“新建”,“保存”等{。同时我们可以在工具条上攄相应的按钮,那么q些都是有相同的功能Q在</span> <span lang="EN-US">JFace</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q然后把它映到不同?/span> <span lang="EN-US">ContributionItem</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">去,而不必ؓ(f)每个部g都写一串处理事件?/span> </font> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们下面q是通过一个简单的例子来说明,?/span> <span lang="EN-US">JFace</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中怎么使用菜单和工hq两U最基本也是最有用?/span> <span lang="EN-US">Contribution Item</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们q个E序写得很傻Q就是一个光U秃的窗口上做了(jin)一个菜单和工具条按钮,功能也只有一个,是每次点一下,弹Z个输入框来问你名字是什么,然后昄一?/span> <span lang="EN-US">Hello, xxx</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先我们q是来写一?/span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">c:(x)<br /><br /><p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt" align="center"></p></span> </font> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt" align="center"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt" align="center"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt" align="center"> </p> <p> </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"> (tng)1</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> (tng)2</span> (tng)<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> (tng)SayHiAction (tng)</span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> (tng)Action (tng){<br /></span><span style="COLOR: #008080"> (tng)3</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> (tng)Shell (tng)shell;<br /></span><span style="COLOR: #008080"> (tng)4</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> (tng)5</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)SayHiAction(Shell (tng)shell) (tng){<br /></span><span style="COLOR: #008080"> (tng)6</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">super</span><span style="COLOR: #000000">();<br /></span><span style="COLOR: #008080"> (tng)7</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.shell (tng)</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (tng)shell;<br /></span><span style="COLOR: #008080"> (tng)8</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.setText(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Say&Hi@Ctrl+H</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080"> (tng)9</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">10</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">11</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)@Override<br /></span><span style="COLOR: #008080">12</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> (tng)run() (tng){<br /></span><span style="COLOR: #008080">13</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)I(yng)nputDialog (tng)input (tng)</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)I(yng)nputDialog(shell, (tng)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Input (tng)your (tng)name</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br /></span><span style="COLOR: #008080">14</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Please (tng)input (tng)your (tng)name (tng)here:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, (tng)</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">, (tng)</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">15</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (tng)(input.open() (tng)</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000"> (tng)Window.OK) (tng){<br /></span><span style="COLOR: #008080">16</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)MessageDialog.openInformation(shell, (tng)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Hello</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, (tng)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Hello, (tng)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">17</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> (tng)input.getValue() (tng)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> (tng)</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> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">19</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">20</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">21</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">22</span> (tng)<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">23</span> (tng)<span style="COLOR: #000000"></span></div> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt" align="center"> <br /> <br /> <em> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码D?/span> <font face="?hu)? MS Song"> <span lang="EN-US"> <span style="mso-no-proof: yes">17</span> </span> </font> </font> </em> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q只是一个很单的</span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">c,没有太多可说的?/span> </font> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">c:(x)<br /><br /></span> </font> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <span lang="EN-US"> <p> <font size="2"> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> </font> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> </span> </p> <p> </p> <p> <font size="2"> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> </font> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p> <font size="2"> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> </font> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p> <font size="2"> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> </font> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </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"> (tng)1</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> (tng)2</span> (tng)<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> (tng)Hiyou (tng)</span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> (tng)ApplicationWindow (tng){<br /></span><span style="COLOR: #008080"> (tng)3</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> (tng)4</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> (tng)SayHiAction (tng)hiaction;<br /></span><span style="COLOR: #008080"> (tng)5</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)Hiyou(Shell (tng)parentShell) (tng){<br /></span><span style="COLOR: #008080"> (tng)6</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">super</span><span style="COLOR: #000000">(parentShell);<br /></span><span style="COLOR: #008080"> (tng)7</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)hiaction</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)SayHiAction(getShell());<br /></span><span style="COLOR: #008080"> (tng)8</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)addMenuBar();<br /></span><span style="COLOR: #008080"> (tng)9</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)addToolBar(SWT.FLAT (tng)</span><span style="COLOR: #000000">|</span><span style="COLOR: #000000"> (tng)SWT.WRAP);<br /></span><span style="COLOR: #008080">10</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">11</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">12</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)@Override<br /></span><span style="COLOR: #008080">13</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> (tng)ToolBarManager (tng)createToolBarManager(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> (tng)style) (tng){<br /></span><span style="COLOR: #008080">14</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)ToolBarManager (tng)toolbar</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)ToolBarManager();<br /></span><span style="COLOR: #008080">15</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)toolbar.add(hiaction);<br /></span><span style="COLOR: #008080">16</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (tng)toolbar;<br /></span><span style="COLOR: #008080">17</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">18</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">19</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)@Override<br /></span><span style="COLOR: #008080">20</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> (tng)MenuManager (tng)createMenuManager() (tng){<br /></span><span style="COLOR: #008080">21</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)MenuManager (tng)menubar</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)MenuManager();<br /></span><span style="COLOR: #008080">22</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)MenuManager (tng)fileMenu</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)MenuManager(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&File</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">23</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)fileMenu.add(hiaction);<br /></span><span style="COLOR: #008080">24</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)menubar.add(fileMenu);<br /></span><span style="COLOR: #008080">25</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (tng)menubar;<br /></span><span style="COLOR: #008080">26</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">27</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">28</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">29</span> (tng)<span style="COLOR: #008000"> (tng) (tng) (tng) (tng) (tng)* (tng)</span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> (tng)args<br /></span><span style="COLOR: #008080">30</span> (tng)<span style="COLOR: #008000"> (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">31</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> (tng)main(String[] (tng)args) (tng){<br /></span><span style="COLOR: #008080">32</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)Hiyou (tng)window</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)Hiyou(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">33</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)window.setBlockOnOpen(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">34</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)window.open();<br /></span><span style="COLOR: #008080">35</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)Display.getCurrent().dispose();<br /></span><span style="COLOR: #008080">36</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">37</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">38</span> (tng)<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">39</span> (tng)<span style="COLOR: #000000"></span></div> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> (tng)</p> <p class="MsoCaption" style="MARGIN: 3pt 0cm 11pt 90pt; TEXT-ALIGN: center" align="center"> <em> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">代码D?/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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">大家可能已经注意C(jin)Q在q里面我们重载了(jin)</span> <span lang="EN-US">createMenuManager</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">两个Ҏ(gu)Q它们的用途就和名字一P一个是用来创徏菜单的,一个是用来创徏工具条的。重载了(jin)q两个方法以后,通过在构造函C调用</span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">addMenuBar</span> <span style="FONT-FAMILY: ?hu)? 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'">addToolBar</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">让工h和菜单显C出来?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">q里值得一提的?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">MenuManager</span> <span style="FONT-FAMILY: ?hu)? 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'">ToolBarManager</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">c,如果大家M?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">API</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">文档的话?x)发现它们都是所谓的</span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">contribution manager</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">Q实C(jin)</span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">IConntributionManager</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">接口Q,你可以通过q些</span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">contribution manager</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">来实现对特定lg的管理(d删除{等Q?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">具体到菜单的创徏Q看?jin)我们上面的代码很明白了(jin),q接调用相?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">MenuManager</span> <span style="FONT-FAMILY: ?hu)? 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'">add</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">Ҏ(gu)?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">d上就可以?jin)?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">JFace</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">?x)自动找到这?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">Action</span> <span style="FONT-FAMILY: ?hu)? 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'">getText</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">Ҏ(gu)讄菜单的文字。如果是有好几层菜单Q那么只要在重新</span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">new</span> <span style="FONT-FAMILY: ?hu)? 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'">MenuManager</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">d到已有的</span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">MenuManager</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">里面可以了(jin)。就象前面代码中的:(x)<br /><br /></span> </font> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </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 /> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">至于工具条就更简单了(jin)Q创Z?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'">ToolBarManager</span> <span style="FONT-FAMILY: ?hu)? 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'">add</span> <span style="FONT-FAMILY: ?hu)? 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'">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; mso-bidi-font-family: 'Courier New'">可以了(jin)?/span> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <h2 style="MARGIN: 7pt 0cm 0pt 54pt"> <font size="3"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">d图标</span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <p> </p> </span> </font> </h2> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">如果菜单只是文字q没有什么,如果你的工具条都是文字是不是?x)显得干巴巴的?其实只要我们?/span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可以了(jin)Q比如你可以自己M个图标保存到</span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的包下面Q我M(jin)一?/span> <span lang="EN-US">hi.gif</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q,然后?/span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的构造函数改写成q样Q?br /><br /><p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"></p></span> </font> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> </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"> (tng)SayHiAction(Shell (tng)shell) (tng){<br /> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span> <span style="COLOR: #0000ff">super</span> <span style="COLOR: #000000">();<br /> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span> <span style="COLOR: #0000ff">this</span> <span style="COLOR: #000000">.shell (tng)</span> <span style="COLOR: #000000">=</span> <span style="COLOR: #000000"> (tng)shell;<br /> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span> <span style="COLOR: #0000ff">this</span> <span style="COLOR: #000000">.setText(</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">Say&Hi@Ctrl+H</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">);<br /> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</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 /> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">hi.gif</span> <span style="COLOR: #000000">"</span> <span style="COLOR: #000000">));<br /> (tng) (tng) (tng) (tng)}</span> </div> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <br /> <br /> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">大家注意最后一句话Q就是ؓ(f)</span> <span lang="EN-US"> <font face="?hu)? MS Song">action</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">讄图标的。然后再q行一下就?x)发现菜单和工具栏都有图标?jin)?/span> </font> </p> <img src ="http://m.tkk7.com/bounce/aggbug/88401.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/bounce/" target="_blank">J2S</a> 2006-12-18 00:26 <a href="http://m.tkk7.com/bounce/archive/2006/12/18/88401.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SWT/JFace开发入门指南(十)(j)〈{帖?/title><link>http://m.tkk7.com/bounce/archive/2006/12/18/88400.html</link><dc:creator>J2S</dc:creator><author>J2S</author><pubDate>Sun, 17 Dec 2006 16:25:00 GMT</pubDate><guid>http://m.tkk7.com/bounce/archive/2006/12/18/88400.html</guid><wfw:comment>http://m.tkk7.com/bounce/comments/88400.html</wfw:comment><comments>http://m.tkk7.com/bounce/archive/2006/12/18/88400.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/bounce/comments/commentRss/88400.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/bounce/services/trackbacks/88400.html</trackback:ping><description><![CDATA[ <h1 style="MARGIN: 11pt 0cm"> <span> <font size="3"> <font style="BACKGROUND-COLOR: #e5e5e5">JFace中的事g模式 <p></p></font> </font> </span> </h1> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">大家好,因ؓ(f)工作的事情搞?jin)一个多月,现在l于暂时安定下来?jin)。这一pd的文章我也会(x)l箋(hu)往下写?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">在这一节中Q我?x)向大家介?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia">JFace</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">中的事g模式。其实我怿q篇文章的读者应该大部分都会(x)接触</span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <a title="" target="_blank"> <font color="#663366">eclipse</font> </a> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">Q这样可能也?x)接触?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <a title="" target="_blank"> <font color="#663366">eclipse</font> </a> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的插件开发。就是没有接触过Q大家也可能?x)有?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <a title="" target="_blank"> <font color="#663366">eclipse</font> </a> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">里面新徏工程的时候出于各U原因(比如好奇?j)?j)点了(jin)</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">plug-in project</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的时候吧。其实作Z个程序员来讲Q保持好奇是很重要的。如果你大概看过一?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia">plug-in project</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的结构,虽然可能不能全部理解Q但是我怿也应该对</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">之类有一些了(jin)解。我们这一节主要就是围l?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">来写的。ؓ(f)?jin)增加可L,我们首先介绍几个名词Q这些名词都可以?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <a title="" target="_blank"> <font color="#663366">eclipse</font> </a> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">的文档中扑ֈ?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <h2 style="MARGIN: 7pt 0cm 0pt 54pt"> <font size="3"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">什么是</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">Action <p></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: ?hu)? 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: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">可以单地理解成一?span style="COLOR: blue">命o(h)</span>。那么它?span style="COLOR: blue">事g</span>有什么关pdQ比如说我点?jin)一个菜单,那么点击本n是一个事Ӟ但是q个事g的媄(jing)响就是相应的命o(h)被执行了(jin)。大家日怋用的一些Y件比?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia">Office</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">都是有菜单和工具栏的Q而一个菜单项和一个工h可能执行的是同一个命令。比?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia">Word</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">里面要新Z个文档的话可以通过</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">?/span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">文g</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">?/span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">菜单下的</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">?/span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">新徏</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">?/span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">实现Q也可以通过点击工具栏上相应的图标实现。这个新建地功能本n?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia">JFace</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">来实现的?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">里面Q?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">可以兌到菜单,工具条,以及(qing)按钮Q也是</span> <span lang="EN-US" style="FONT-FAMILY: Georgia">Button</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: Georgia; mso-hansi-font-family: Georgia">Q。当然关于如何关联,我们?x)在后面向大家详l介l?/span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <p> </p> </span> </font> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">。当然实际上你写E序的时候必自己来实现q个接口Q写?gu)q</span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">cL?/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: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q它也是事g触发以后执行的代码。其他的Ҏ(gu)都是一些辅助性的Ҏ(gu)Q不是我们要x(chng)的重炏Vؓ(f)?jin)能够将_֊集中在我们所x(chng)的事情上Q通常我们不是实现</span> <span lang="EN-US">IAction</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">接口Q而是通过l承</span> <span lang="EN-US">org.eclipse.jface.action.Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q个抽象cL实现</span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> </span> </font> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <font size="3"> <strong>Hello,Action!</strong> </font> </span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <font size="3"> <p> </p> </font> </span> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <h2 style="MARGIN: 7pt 0cm 0pt 54pt"> <p> </p> <h2 style="MARGIN: 7pt 0cm 0pt 54pt"> <p> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <font size="3"> </font> </span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <font size="3"> <p> </p> </font> </span> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> </h2> <p> </p> <p> </p> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <font size="3"> </font> </span> <span lang="EN-US" style="FONT-FAMILY: Georgia"> <font size="3"> <p> </p> </font> </span> <p> </p> </h2> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <font size="2"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">首先我们先不用L(fng)面,先定义一个最单的</span> <span lang="EN-US">Action</span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">cR?/span> </font> </p> <p> </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"> (tng)1</span> (tng)<span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> (tng)HelloAction (tng)</span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> (tng)Action{<br /></span><span style="COLOR: #008080"> (tng)2</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> (tng)Shell (tng)shell;<br /></span><span style="COLOR: #008080"> (tng)3</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)<br /></span><span style="COLOR: #008080"> (tng)4</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)HelloAction(Shell (tng)shell) (tng){ (tng) (tng) (tng) (tng)<br /></span><span style="COLOR: #008080"> (tng)5</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">super</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&Hello</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,Action.AS_PUSH_BUTTON);<br /></span><span style="COLOR: #008080"> (tng)6</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</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"> (tng)7</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080"> (tng)8</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> (tng)9</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">10</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)@Override<br /></span><span style="COLOR: #008080">11</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> (tng)run() (tng){<br /></span><span style="COLOR: #008080">12</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)MessageDialog.openInformation(shell, (tng)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Hello</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, (tng)</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> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">14</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)<br /></span><span style="COLOR: #008080">15</span> (tng)<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">16</span> (tng)<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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> <br />代码D?/span> <font face="Times New Roman"> <span lang="EN-US"> <span style="mso-no-proof: yes">1</span> </span> <span lang="EN-US">5 <p></p></span> </font> </em> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p class="MsoBodyText" style="MARGIN: 0cm 0cm 11pt 54pt"> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q段代码其实应该q是很好L的。带参的构造函数带q来一?/span> <span lang="EN-US"> <font face="Times New Roman">Shell</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">实例Q?/span> <span lang="EN-US"> <font face="Times New Roman">run()</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ҏ(gu)说明?jin)这?/span> <span lang="EN-US"> <font face="Times New Roman">Action</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的功能就是显CZ个对话框。第</span> <span lang="EN-US"> <font face="Times New Roman">5</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">行中的代码调用了(jin)父类的构造函敎ͼ其中W一个参数是</span> <span lang="EN-US"> <font face="Times New Roman">Action</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">对应的文本,前面?/span> <span lang="EN-US"> <font face="Times New Roman">&</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">W号表明?/span> <span lang="EN-US"> <font face="Times New Roman">H</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是热键,而第二个参数则是一个风格参数。如果大家l向后看的话Q就?x)发现这?/span> <span lang="EN-US"> <font face="Times New Roman">Action</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">被附加在?jin)一个按钮上面,而按钮上昄的文本就?/span> <span lang="EN-US"> <font face="Times New Roman">Hello</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q如果你定义的风g?/span> <span lang="EN-US"> <font face="Times New Roman">AS_PUSH_BUTTON</font> </span> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的话׃(x)发现按钮已经不是一个纯_的按钮?jin),而是一个单选钮。相应的其他风格可以参照</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"> (tng)1</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> (tng)2</span> (tng)<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> (tng)HelloJface (tng)</span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> (tng)ApplicationWindow (tng){ (tng) (tng) (tng) (tng) (tng) (tng)<br /></span><span style="COLOR: #008080"> (tng)3</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)HelloJface(Shell (tng)shell) (tng){<br /></span><span style="COLOR: #008080"> (tng)4</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">super</span><span style="COLOR: #000000">(shell);<br /></span><span style="COLOR: #008080"> (tng)5</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080"> (tng)6</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng)@Override<br /></span><span style="COLOR: #008080"> (tng)7</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> (tng)Control (tng)createContents(Composite (tng)parent) (tng){<br /></span><span style="COLOR: #008080"> (tng)8</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)HelloAction (tng)action</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)HelloAction(parent.getShell());<br /></span><span style="COLOR: #008080"> (tng)9</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)ActionContributionItem (tng)aci</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)ActionContributionItem(action);<br /></span><span style="COLOR: #008080">10</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)aci.fill(parent);<br /></span><span style="COLOR: #008080">11</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng) (tng)</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (tng)parent;<br /></span><span style="COLOR: #008080">12</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng)} (tng) (tng)<br /></span><span style="COLOR: #008080">13</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng)</span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">14</span> (tng)<span style="COLOR: #008000"> (tng) (tng) (tng) (tng)* (tng)</span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> (tng)args<br /></span><span style="COLOR: #008080">15</span> (tng)<span style="COLOR: #008000"> (tng) (tng) (tng) (tng)</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">16</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng)</span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> (tng)main(String[] (tng)args) (tng){<br /></span><span style="COLOR: #008080">17</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">18</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng)HelloJface (tng)demo (tng)</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (tng)</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> (tng)HelloJface(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">19</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng)demo.setBlockOnOpen(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">20</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng)demo.open();<br /></span><span style="COLOR: #008080">21</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng) (tng) (tng) (tng) (tng)Display.getCurrent().dispose();<br /></span><span style="COLOR: #008080">22</span> (tng)<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">23</span> (tng)<span style="COLOR: #000000"> (tng) (tng) (tng)}<br /></span><span style="COLOR: #008080">24</span> (tng)<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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> <br />代码D?/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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-bidi-language: HE; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">和前面一节的代码相比Q我们只是修改了(jin)</span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-fareast-font-family: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">Ҏ(gu)。首先创Z(jin)一?/span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-fareast-font-family: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">的实例,然后又创Z(jin)一?/span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-fareast-font-family: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">的实例,最后调用了(jin)q个实例?/span> <span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-fareast-font-family: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: ?hu)? mso-bidi-language: AR-SA; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN">Ҏ(gu)按钮添加到H口中,q就是全部了(jin)。是不是很简单呢Q程序运行出来的效果如下图:(x)</span> <br /> </p> <p align="center"> <br /> <img alt="" src="http://blog.csdn.net/images/blog_csdn_net/jayliu/121129/o_helloaction.JPG" align="middle" /> <br /> </p> <p class="MsoCaption" style="MARGIN: 3pt 0cm 11pt 90pt; TEXT-ALIGN: center" align="center"> <em> <span style="FONT-FAMILY: ?hu)? 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: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">可能看了(jin)q个例子Q你?x)认?/span> <span lang="EN-US"> <font face="Times New Roman">ActionContributionItem</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q个c表C的是一个按钮了(jin)。但是实际上q不是的Q它在图形界面上表示成什么样子,随着不同?/span> <span lang="EN-US"> <font face="Times New Roman">fill</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">调用又有不同。在下一节中Q我?x)向大家深入介?/span> <span lang="EN-US"> <font face="Times New Roman">Contribution Item</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">以及(qing)</span> <span lang="EN-US"> <font face="Times New Roman">JFace</font> </span> <span style="FONT-FAMILY: ?hu)? mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的菜单Q工h{的应用。这一节就到这里结束了(jin)Q因为刚刚换?jin)工作环境,有很多事情需要去做,所以写得比较短Q请大家见谅Q)(j)?/span> <span lang="EN-US"> <p> </p> </span> </p> <img src ="http://m.tkk7.com/bounce/aggbug/88400.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/bounce/" target="_blank">J2S</a> 2006-12-18 00:25 <a href="http://m.tkk7.com/bounce/archive/2006/12/18/88400.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> վ֩ģ壺 <a href="http://directzx.com" target="_blank">˳˳߹ۿ</a>| <a href="http://www2626cf.com" target="_blank">Av츾߳30p</a>| <a href="http://jyzs888.com" target="_blank">AVһţţ</a>| <a href="http://whknd.com" target="_blank">ձƵѸһ18</a>| <a href="http://minliusoft.com" target="_blank">޹СƵƷþþ </a>| <a href="http://www-774220.com" target="_blank">Ļպר</a>| <a href="http://yhanalati.com" target="_blank">һһëƬ</a>| <a href="http://jiajuco.com" target="_blank">ɫͼƬС˵</a>| <a href="http://10242016.com" target="_blank">aëƬ</a>| <a href="http://79909d.com" target="_blank">޺һ</a>| <a href="http://714747.com" target="_blank">Ƭ߹ۿѴȫӰ </a>| <a href="http://www04ggg.com" target="_blank">޳ɫӰԺ</a>| <a href="http://www321fafa.com" target="_blank">ѹۿ</a>| <a href="http://x5k9.com" target="_blank">ľƷAVƬ</a>| <a href="http://chaikexin.com" target="_blank">vƬ߹ۿ</a>| <a href="http://cc006.com" target="_blank">պ߹ۿ</a>| <a href="http://yuejiju.com" target="_blank">רëƬ߳ˮ</a>| <a href="http://3344by.com" target="_blank">ֻˬһëƬѹۿ</a>| <a href="http://www04ggg.com" target="_blank">ɫ͵͵</a>| <a href="http://xxnxgay.com" target="_blank">ƬѸƬ</a>| <a href="http://56aaaa.com" target="_blank">ŷһղ</a>| <a href="http://77663499.com" target="_blank">Ʒһ </a>| <a href="http://918989b.com" target="_blank">޴ɫAvר</a>| <a href="http://sztsa.com" target="_blank">ȫƵѹۿ߿</a>| <a href="http://huahui1866.com" target="_blank">ҹƵ</a>| <a href="http://jinmenonline.com" target="_blank">޾Ʒ㶮߹ۿ</a>| <a href="http://tianmao920.com" target="_blank">h߿Ƶվ</a>| <a href="http://yisaoma.com" target="_blank">˳ɵӰվƷ</a>| <a href="http://f2dai.com" target="_blank">һëƬaѲɫ</a>| <a href="http://0101av.com" target="_blank">ɫַ</a>| <a href="http://zbhongtai.com" target="_blank">պAVһ</a>| <a href="http://xfmkt.com" target="_blank">һƷ˾þ</a>| <a href="http://a666999.com" target="_blank">eeussӰԺwww</a>| <a href="http://sdsupuchem.com" target="_blank">޾aaվ</a>| <a href="http://9981tv.com" target="_blank">AAAձ߲ѹۿ</a>| <a href="http://35419470.com" target="_blank">޴ɫƵ</a>| <a href="http://8mav938.com" target="_blank">99þþƷ</a>| <a href="http://www664660a.com" target="_blank">޳ҹӰ</a>| <a href="http://yhanalati.com" target="_blank">ҹҹƵ</a>| <a href="http://1897tao.com" target="_blank">avһվ²</a>| <a href="http://xmllhb.com" target="_blank">޹ƷۺϾþ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>