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.

16.3 Stompin’ at the Savoy, or The Swing Paradigm343While this may look like a lot of extra junk just to say “Hello, world,” rememberthat a GUI is not just providing output in fancy windows, but alsom<strong>on</strong>itoring and resp<strong>on</strong>ding to a wide variety of user inputs—a capability ofwhich we make little or no use in this example. But you can see some of thisextra capability—grab the lower left corner of the window frame and expandand resize the window.16.3STOMPIN’ AT THE SAVOY, OR THE SWING PARADIGMWhen we say “Swing,” we generally mean the set of classes in the javax.swingpackage and its subpackages (such as javax.swing.table). The packages arelibraries of code that give you predefined classes from which you can c<strong>on</strong>structa GUI for your applicati<strong>on</strong>. The programs you write will be written in Java,the syntax will look like Java, but there will be a lot of creati<strong>on</strong> of classes, usesof interfaces, implementati<strong>on</strong>s of abstract classes, and a variety of method callsthat all deal with these Swing classes.So what’s going <strong>on</strong> with all this stuff? What can we expect to do, see,write? In most applicati<strong>on</strong>s that a programmer writes, it is the job of the programmerto design and write the code for the main executi<strong>on</strong> path of the program.“Yes, every program has a beginning, middle, and an end” (with apologiesto “Seymour and his frozen yoghurt stand,” from Sesame Street). But it’s notquite the same with Swing. While it does have to have a beginning, middle,and end (these are, after all, basic V<strong>on</strong> Neumann architecture machines), thebig difference is that you do not have to write most of the c<strong>on</strong>trol logic; itcomes as part of the Swing set.Look at it this way. With Swing, as with other GUI toolkits, you d<strong>on</strong>’thave to write code to deal with the mouse, keyboard shortcuts, or paintingcharacters <strong>on</strong>to a graphical screen. You d<strong>on</strong>’t have to write all the codeassociated with a butt<strong>on</strong> press, because, while it seems simple enough, a butt<strong>on</strong>press is really a quite complex user interacti<strong>on</strong>, involving repainting of thebutt<strong>on</strong>’s border, possibly its shading or changing its ic<strong>on</strong>, coordinating thatwith the mouse presses and releases, and deciding whether the releases happenwithin or without the boundaries of the butt<strong>on</strong>—all this and more, just for asimple butt<strong>on</strong> press. All this has been d<strong>on</strong>e for you, and packaged up intoSwing classes.

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

Saved successfully!

Ooh no, something went wrong!