| 1 | How to Write, Compile and Execute a SWT Application |
|---|
| 2 | =================================================== |
|---|
| 3 | =================================================== |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | Introduction |
|---|
| 7 | ============ |
|---|
| 8 | |
|---|
| 9 | I have spent today looking at SWT and Eclipse as potential |
|---|
| 10 | technologies for WCKER's implementation. |
|---|
| 11 | |
|---|
| 12 | SWT is a replacement GUI API for Java (instead of the usual |
|---|
| 13 | AWT/Swing) and Eclipse is an integrated IDE for Java development |
|---|
| 14 | which can also do CVS stuff. |
|---|
| 15 | |
|---|
| 16 | For "looking at", read "trying to get to work" ! :-) |
|---|
| 17 | I didn't help that the instructions in the online tutorials |
|---|
| 18 | are wrong, and the standard tutorial example does not itself |
|---|
| 19 | work. Finally, I managed to find an online forum where some |
|---|
| 20 | of these issues were discussed ..... phew!!!!!! |
|---|
| 21 | |
|---|
| 22 | The next section documents my hard-won findings of how to |
|---|
| 23 | produce a working SWT application. |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | Developing a SWT application |
|---|
| 27 | ============================ |
|---|
| 28 | |
|---|
| 29 | Source Code |
|---|
| 30 | ----------- |
|---|
| 31 | |
|---|
| 32 | import org.eclipse.swt.widgets.*; |
|---|
| 33 | import org.eclipse.swt.*; |
|---|
| 34 | /**/ |
|---|
| 35 | public class SWTHello { |
|---|
| 36 | public static void main(String[] args) { |
|---|
| 37 | |
|---|
| 38 | MessageBox m = new MessageBox(new Shell()); |
|---|
| 39 | m.setMessage("Hello, World"); |
|---|
| 40 | m.open(); |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | Compilation |
|---|
| 45 | ----------- |
|---|
| 46 | |
|---|
| 47 | javac -classpath /usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt.jar:/usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt-pi.jar SWTHello.java |
|---|
| 48 | |
|---|
| 49 | Notes: |
|---|
| 50 | (1) Only one of the two necessary JAR files was mentioned in the tutorials. |
|---|
| 51 | (2) /usr/eclipse is the local installation root of Eclipse |
|---|
| 52 | (3) It is also possible to supply these command line arguments through |
|---|
| 53 | the CLASSPATH environment variable. |
|---|
| 54 | |
|---|
| 55 | Execution |
|---|
| 56 | --------- |
|---|
| 57 | |
|---|
| 58 | java -classpath /usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt.jar:/usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/ws/gtk/swt-pi.jar:. -Djava.library.path=/usr/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.1/os/linux/x86/ SWTHello |
|---|
| 59 | |
|---|
| 60 | Note: |
|---|
| 61 | |
|---|
| 62 | (1) As SWT also uses a native (i.e. 'C') library, then one has to not only specify where Java |
|---|
| 63 | objects can be found but also 'C' objects i.e. more variables to get wrong. |
|---|
| 64 | |
|---|
| 65 | (2) It is also possible to supply these command line arguments through |
|---|
| 66 | the CLASSPATH and LD_LIBRARY_PATH environment variables. |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | Conclusion |
|---|
| 70 | ========== |
|---|
| 71 | |
|---|
| 72 | I am able now to build and run small SWT applications, both inside and outside the |
|---|
| 73 | Eclipse IDE. Only the command-line solutions are provided for succinctness. The next |
|---|
| 74 | stage is to assess the ease of implementing some initial WCKER pages in SWT. |
|---|
| 75 | |
|---|
| 76 | Eclipse also contains an interactive graphical Java debugger (to be checked out): this is |
|---|
| 77 | particularly good news (fingers crossed) as the stand-alone Java debuggers I tried out earlier |
|---|
| 78 | in the project were universally poor! |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | David |
|---|