13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

17.2 The IBM SWT Toolkit381Microsoft Windows. If you have ever written an X Window or MicrosoftWindows applicati<strong>on</strong> in straight C (without a GUI framework library or classlibrary), you have written a main() functi<strong>on</strong> that c<strong>on</strong>tains an event loop. SWTactually puts simple method calls around this core message queue event loop.We’ll cover the details of this in the next secti<strong>on</strong> where we introduce theDisplay and Shell classes.17.2.6 “Hello, world” SWT StyleSWT c<strong>on</strong>sists mainly of classes that represent c<strong>on</strong>trols—such as butt<strong>on</strong>s, textareas, scrollbars, and so <strong>on</strong>—and layout managers which are much like layoutmanagers in Swing. But there are two other classes: Display, which modelsthe interface between your Java applicati<strong>on</strong> and the underlying windowingsystem, and Shell, which effectively represents a single window.The applicati<strong>on</strong> in Example 17.1 is a parallel to the simple Swing programin the last chapter (Example 16.1).This simple program, like its parallel in the Swing chapter, is deceptive.Sure, this is a lot of code to say “Hello, world” but it is because what we aresetting up here is an event-driven program that must resp<strong>on</strong>d to any validuser input.17.2.6.1 Setting Up to Run an SWT <str<strong>on</strong>g>Applicati<strong>on</strong></str<strong>on</strong>g>One advantage of Swing that we haven’t pointed out up to now is that it is partof every Java runtime (well, not gcj; more <strong>on</strong> that later), so you have all theclasses <strong>on</strong> your classpath without any special setup. Not so with SWT. Theexact procedure for setting up to run an SWT applicati<strong>on</strong> depends <strong>on</strong> whatdevelopment envir<strong>on</strong>ment you are using.There is an excellent set of directi<strong>on</strong>s for running an SWT applicati<strong>on</strong>under Eclipse in the SWT FAQ. 8 No matter what your envir<strong>on</strong>ment is, thereis a basic series of steps:1. Download the Eclipse SDK.2. Install it.8. http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-swt-home/faq.html?rev=1.83c<strong>on</strong>tent-type=text/html#standal<strong>on</strong>e. Note that this link is tothe current revisi<strong>on</strong> in CVS as of this writing. You should take a look at the parent page to seeif there is a newer revisi<strong>on</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!