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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

380Chapter 17Other Ways: Alternatives to Swing17.2.3 Portability: Better and WorseHow about portability? Well, it depends <strong>on</strong> what “portability” means to you.If portability means “looks and runs the same <strong>on</strong> all platforms,” then Swingoffers better portability. If portability means “runs <strong>on</strong> all platforms for whichthere is a Java runtime,” then Swing offers better portability. If portabilitymeans “looks like a native applicati<strong>on</strong> <strong>on</strong> all supported platforms,” then SWTis your choice. Make your selecti<strong>on</strong> accordingly.TIPThe bottom line: If you <strong>on</strong>ly learn <strong>on</strong>e Java GUI, make it Swing.17.2.4 The Rest of the ChapterThe rest of this chapter will be devoted to describing the basic classes of SWTby c<strong>on</strong>verting <strong>on</strong>e of the applicati<strong>on</strong> classes from the previous chapter fromSwing to SWT. We will not attempt to explain the operating principles ofGUIs. For an introducti<strong>on</strong> to GUI programming, see the previous chapter <strong>on</strong>Swing. It introduces the c<strong>on</strong>cepts and programming principles for GUIprogramming in Java. SWT is functi<strong>on</strong>ally similar, although quite spartan,providing <strong>on</strong>ly basic windows, c<strong>on</strong>trols, and events.Eclipse also c<strong>on</strong>tains a family of higher level user interface classes, knowncollectively as JFace, that provide UI features such as dialogs, wizards, f<strong>on</strong>thandlers, and images. We will not cover JFace in this book.17.2.5 SWT: Close to the MetalSWT breaks some of the Java c<strong>on</strong>tract. For example, you cannot rely <strong>on</strong> garbagecollecti<strong>on</strong> to clean up SWT objects. Any SWT object you create with new mustbe explicitly destroyed with a call to the dispose() method. Why? Since SWTis implemented with native methods, the low-level implementati<strong>on</strong> allocatesnative OS data structures and objects that must be explicitly freed. Since theJava garbage collector cannot be relied up<strong>on</strong> to collect objects at a certain time(or ever, for that matter), these allocati<strong>on</strong>s can result in memory leaks andaddress space c<strong>on</strong>flicts. As we shall see, however, SWT is well designed tominimize the amount of this that you need to worry about.SWT is also close to the metal in the sense that it does not abstract theunderlying message-based event system that drives both X Window and

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

Saved successfully!

Ooh no, something went wrong!