精華區beta TTU-I90B 關於我們 聯絡資訊
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.examples/doc-html/swt _manual_setup.html?rev=1.21 SWT standalone examples setup Importing example source *** In the following description, substitute the location in which you install ed Eclipse for INSTALLDIR *** Import the example code and all its required resources into your workspace: 1. Create a Java Project called "SWT Examples". 2. Select the project "SWT Examples" in the Packages view. 3. Select the File > Import menu, then select Zip File from the subsequent dialog and click Next. 4. Locate the source zip file for the SWT examples. For example: * win32: INSTALLDIR\eclipse\plugins\org.eclipse.sdk.examples.source_ 3.0.0\src\org.eclipse.swt.examples_3.0.0\swtexamplessrc.zip * *ix: INSTALLDIR/eclipse/plugins/org.eclipse.sdk.examples.source_3. 0.0/src/org.eclipse.swt.examples_3.0.0/swtexamplessrc.zip 5. Click Finish. 6. Select the File > Import menu, then select Zip File from the subsequent dialog and click Next. 7. Locate the jar file for the SWT examples. For example: * win32: INSTALLDIR\eclipse\plugins\org.eclipse.swt.examples_3.0.0\s wtexamples.jar * *ix: INSTALLDIR/eclipse/plugins/org.eclipse.swt.examples_3.0.0/swt examples.jar 8. Expand the top level directory of the jar file (/), uncheck "META-INF", and click Finish. 9. In the resulting "Overwrite?" prompter click No To All so that only non- class resources will be imported. Now you need to compile the SWT examples. In order to do this, you must add th e SWT jar(s) to the compile path: 1. Select the project "SWT Examples" in the Packages view, and from its con text menu select Properties. 2. Select the Java Build Path page, and then select its Libraries tab. 3. Click on the Add External JARs... button. 4. Locate the swt jar for the platform on which you wish to run: * win32: INSTALLDIR\eclipse\plugins\org.eclipse.swt.win32_3.0.0\ws\w in32\swt.jar * gtk: INSTALLDIR/eclipse/plugins/org.eclipse.swt.gtk_3.0.0/ws/gtk/s wt.jar * motif: INSTALLDIR/eclipse/plugins/org.eclipse.swt.motif_3.0.0/ws/m otif/swt.jar * photon: INSTALLDIR/eclipse/plugins/org.eclipse.swt.photon_3.0.0/ws /photon/swt.jar * macosx: INSTALLDIR/eclipse/plugins/org.eclipse.swt.carbon_3.0.0/ws /carbon/swt.jar 5. Click on OK. NOTE: For some platforms, such as GTK, more than one jar is required to run SW T (on GTK there is a swt.jar and a swt-pi.jar and a swt-mozilla.jar file). In this case all of the required jars must be added to the class path. This is do ne by repeating the steps above for each jar file. All jar files are located i n the same directory/folder. At this point your SWT examples should be compiled without any errors. Check t he Tasks view for errors. If you get an error like "java.lang.Object not found " it means you have not configured a JRE. Go to the Window > Preferences dialo g and select the Java > Installed JREs preference page and ensure that a JRE i s installed and that the path to the JRE is correct. Running the Example Now you have to configure Eclipse to run the example. This requires putting th e SWT JNI libraries on the library path so that the VM can find them: 1. Open the Java perspective. 2. In the Packages view, select the main class that you want to run. For ex ample, the main class for the Address Book example is org.eclipse.swt.exam ples.addressbook.AddressBook. 3. Select Run > Run... from the main menu. 4. In the Launch Configurations dialog that appears, select Java Applicatio n and click on the New button. 5. Fill in the Name, Project and Main class fields according to the example that you wish to run. 6. Select the Arguments tab. In the VM Arguments area specify the location of the SWT library depending on your target platform as follows: * win32: -Djava.library.path=INSTALLDIR\plugins\org.eclipse.swt.win3 2_3.0.0\os\win32\x86 * linux gtk: -Djava.library.path=INSTALLDIR/eclipse/plugins/org.ecli pse.swt.gtk_3.0.0/os/linux/x86 * linux motif: -Djava.library.path=INSTALLDIR/eclipse/plugins/org.ec lipse.swt.motif_3.0.0/os/linux/x86 * solaris motif: -Djava.library.path=INSTALLDIR/eclipse/plugins/org. eclipse.swt.motif_3.0.0/os/solaris/sparc * aix motif: -Djava.library.path=INSTALLDIR/eclipse/plugins/org.ecli pse.swt.motif_3.0.0/os/aix/ppc * hpux motif: -Djava.library.path=INSTALLDIR/eclipse/plugins/org.ecl ipse.swt.motif_3.0.0/os/hpux/PA_RISC * photon qnx: -Djava.library.path=INSTALLDIR/eclipse/plugins/org.ecl ipse.swt.photon_3.0.0/os/qnx/x86 * macosx: -Djava.library.path=INSTALLDIR/eclipse/plugins/org.eclipse .swt.carbon_3.0.0/os/macosx/ppc 7. Click on the Run button. Examples Overview Consult the documentation of each individual example for the name of its main class and additional details. The following examples are included in the swtex amples.jar: * Address Book * Clipboard * Controls * Custom Controls * File Viewer * Hello World [1-5] * Hover Help * Image Analyzer * Java Syntax Viewer * Layouts * Text Editor Copyright IBM Corporation and others 2000, 2004. All Rights Reserved.