Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

Magercise 1
Installation and SwingSet Demonstration

[Help | API Docs | Short Course | Magercises]

In this magercise you will install the Swing package and take a tour of the SwingSet demonstration. Swing is a new set of user interface components based on the JavaTM 1.1.2+ Abstract Window Toolkit (AWT). The new components are written entirely using the Java® 2 platform and are part of the JavaTM Foundation Classes (JFC). After you have installed Swing, the magercise will introduce and demonstrate the various Swing components.

If you are using the Java® 2 platform, you do not need to download the Swing classes as they are part of the JavaTM Development Kit (JDK). You can skip the first couple steps of the exercise.

Magercise 1 Prerequisites

None.

Tasks:

  1. Download the latest version of the Swing early access release from Sun.

  2. Installation requires you to uncompress/untar or unzip the file acquired. Do not extract the class files from the *.jar files that are within the Swing download.

  3. Before running the demonstration, take a look at the online Swing documentation, and bookmark it. Along with information about Swing, the online JavaDoc API material is here. You need to open and bookmark the file: SwingInstallationDirectory/doc/api/packages.html .

    After bookmarking the page, you can browse through the documentation of the API material.

  4. To run the demonstration, from a command shell with JDK 1.1.x, you need to setup some environment variables:

    For Solaris:

    • setenv JDKHOME JDKInsallationDirectory
    • cd SwingInstallationDirectory
    • cd examples
    • cd SwingSet
    • runnit

    For Windows 95/NT:

    This assumes the JDK is installed in c:\jdk1.1.7 and Swing is located in c:\swing-1.1.

    • set JDKHOME=C:\jdk1.1.7
    • set CLASSPATH=%JDKHOME%\lib\classes.zip
    • set PATH=%JDKHOME%\bin;%PATH%
    • set SWINGHOME=C:\swing-1.1
    • cd C:\swing-1.1
    • cd examples
    • cd SwingSet
    • runnit

    For Java 2 users:

    The SwingSet demo comes with the Java® 2 platform. As long as you are set up to run the runtime environment, you just need to start the demo.

    • cd JDKInsallationDirectory
    • cd demo
    • cd jfc
    • cd SwingSet
    • java SwingSet

    This brings up the initial SwingSet demonstration screen.

This magercise does not create a program, but executes Swing's SwingSet demo. When first started, it will look something like:

Note: Clicking on the image will bring-up a larger version of the image.

  1. To demonstrate some of the familiar, select the Buttons tab. This shows three of the button types supported by Swing: Text Buttons, Image Buttons, and Rollover Image Buttons.

    Notice that the text buttons have an accelerator key. If you select ALT-accelerator key, the button becomes activated. This is part of the added keyboard control support in Swing.

    For the image buttons: They exist in Swing. If you select the different image buttons, you'll notice that the second and third buttons show a green arrow image when depressed, while the first doesn't. This demonstrates some of the different behavior you can provide. Also, if you select the Enabled toggled on the right, so that it is unchecked, this demonstrates the different disabled features you can use.

    For the rollover image buttons: When you move the mouse over each button the image changes. Also, if you change the Text Position by moving the ball around on the upper right, you can move the text relative to the image location. The Content Alignment tells the image/text where to go when additional space is available, so select the 10 toggle, and then relocate the content. (This is more discernable with components other than buttons).

  2. For the RadioButtons, and Checkboxes tabs: The key differences between AWT and Swing is there is no CheckboxGroup object. The components are separate objects. There is however a ButtonGroup object to group radio buttons together. Another difference between AWT and Swing is that you can use an image as the toggle object, instead of a checkbox. As the screens show, this can create some interesting interfaces. The ToggleButtons tab shows a third kind of toggle control.

    For the Labels tab: The only things new there are that a label can have an image on it and a keyboard accelerator for a label can move the input focus to an associated component.

  3. Some of the new components introduced by Swing can be found under the Borders, ComboBox, TableView, BorderedPane, SplitPane and ToolTips tabs. The cow shown under the ToolTips tab acts like an image map, where certain areas of the cow show different tool tips. Rest your mouse and see the different ones. Be sure to find the area that has "Got Milk?" as its tool tip.

  4. Selecting the Internal Frame tab shows off Swing's Dialog-like object. Here, when you drag the window around, you'll quickly notice it will not go outside the demo's area. Also, you can create other frames by selecting the Make button. If you change the Layer input you'll also notice the support for z-ordering, or layering of objects.

    Before leaving this tab, select another Look & Feel from the Options menu. Notice how this changes the appearance of the different components. This is Swing's Pluggable Look & Feel capabilities. Basically, at run-time, you can permit users to change the appearance of the interface from the default Metal-style interface to a Windows-95 interface, to a Motif interface, or any custom interface. Or, you can just enable a different Look & Feel all the time.

  5. The ListBox tab shows off some new capabilities of lists. The most obvious addition here is the ability to have images in the list. Selecting an item also demonstrates that you can change what is shown when an item becomes selected.

    Find out how much a cola, cake, fruit pop, watermelon, and a radish cost, combined.

  6. Under the Menus & ToolBars tab you'll find the new ToolBar component, and notice that menus can now have images along with text for menu items, even on the menu bar. While looking at the menus, find the names of three cats. While toolbars are draggable by default, this one isn't.

  7. The last three tabs we'll look at are TreeView, ProgressBar, and HTML Text. TreeView demonstrates an hierarchical viewer that is now a standard component. For the Progress Bar, if you select the Start Loading Text button, you'll notice its behavior, as it loads in a file from disk. With the HTML Text object, it supports HTML 3.2 display like images, text, and hot links.

  8. At your leisure, stop by the other tabs. You'll get to create the components in the remaining magercises. So, just get a feel for what's out there now. When you're done, select File then Exit to close the demonstration.

Where help exists, the task numbers above are linked to the step-by-step help page.

Magercise 2

Short Course

About This Short Course

Copyright © 1998-1999 MageLang Institute. All Rights Reserved.


[ This page was updated: 19-Nov-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.