New to Java? We'll help you get started with our revised beginner's tutorial, or our free online textbook.
|
Get the latest Java books |
|
h t t p : / /w w w . j a v a c o f f e e b r e a k . c
o m /
|
Menu Articles Using Java Applets Looking for Java resources? Check out the Java Coffee Break directory! |
Learning about SwingThe best way to learn about Swing is to actually use an application that has a Swing GUI. A good starting place is the SwingSet demo, that is shipped with JDK1.2. If you don't already have JDK1.2 installed, you'll need to install it to work with Swing applications. The latest version of JDK1.2 can be found at http://java.sun.com/ Running the SwingSet DemoThe demo can be found in the demo/jfc/SwingSet directory, located under your JDK1.2 installation directory. From a DOS Prompt or shell window, change to this directory then run the SwingSet application. c:\>cd \jdk1.2\demo\jfc\SwingSet c:\jdk1.2\demo\jfc\SwingSet>java SwingSet The first thing you should notice is that the demonstration takes awhile to load - a window with a progress bar will be shown as the demonstration loads. The progress bar component is a nice way of letting users know that a slow application is still chugging along, and hasn't fallen over ;) Once the demonstration loads, you can then click on different tab buttons to view the various components and behaviors that make up the Swing API. Take some time to experiment and click on some of the components - you'll be pleasantly surprised at the functionality that's available. While you have the SwingSet demo running, take a look at the menu options. You can now trigger a menu using only the keyboard (e.g. ALT-F for the File menu). Take a look at the Options menu, and the radio buttons provided. These allow you to dynamically change the look-and-feel of components at run-time. Switch between the Java L&F (also referred to as 'Metal'), and the Motif/Windows L&F. You'll notice that all of the components (including menus) change appearance. This is a very powerful feature of Swing, and gives users control over which GUI style is used. Personally, I think that the Metal L&F is very comfortable to use, though end-users may prefer to stick with Windows L&F. Once you've had a play around with Swing, you'll be reluctant to go back to the older AWT components. Remember however that only the Java 2 Platform supports Swing (though older Java 1.1 Virtual Machines can still run Swing if you include the components in the codebase of your application). For the moment at least, it rules out developing Swing applets, unless the Java Plug-in is used to run them under a Java 2 Virtual Machine. |
||||
|