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
 

Help is available for each task.

Task 1

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

Task 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.

Task 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.

Follow the trail, based upon which browser you are using:
  • Internet Explorer 3.0/4.0
    • Select File -> New Window to open up a second browser window
    • In second window, select File -> Open -> Browse, enter the name of the Swing installation parent directory, Enter, swing-1.1, Enter, doc, Enter, api, Enter, packages.html, Enter, and select OK.
    • Select Favorites -> Add to Favorites to bookmark this page.
  • Netscape Navigator 2.0/3.0
    • Select File -> New Web Browser to open up a second browser window
    • Select File -> Open File in Browser, enter the name of the Swing installation parent directory, Enter, swing-1.1, Enter, doc, Enter, api, Enter, packages.html, Enter, and select OK.
    • Select Bookmark -> Add Bookmark.
  • Netscape Navigator 4.0 (Communicator)
    • Select File -> New -> Navigator Window to open up a second browser window
    • Select File -> Open Page -> Choose File, enter the name of the Swing installation parent directory, Enter, swing-1.1, Enter, doc, Enter, api, Enter, packages.html, Enter, and select Open.
    • Select Communicator -> Bookmarks -> Add Bookmark.

If the Swing installation directory isn't swing-1.1, replace with the appropriate location.

If you are using the Swing classes with Java® 2, be sure to bookmark the standard Java® 2 platform libraries.

Task 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 Java® 2 platform. As long as you are setup 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.

You may find it helpful to place the commands in a shell script (UNIX) or batch file (Windows).

Also, the README.txt file in the Swing installation directory contains additional setup information.

Task 5

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).

The appropriate accelerator key for shortcuts is platform specific.

Task 6

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 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 is a label can have an image on it and a keyboard accelerator for a label can move the input focus to an associated component.

Task 7

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.

Task 8

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. You can only use the Windows-style Look & Feel on Windows platforms.

Task 9

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.00

Task 10

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 most toolbars are draggable by default, this one isn't.

Ridley, Quigley, and Kizmet.

Task 11

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.

Task 12

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.

Be sure to read the README.txt file in the SwingSet directory for help using the example.

Return to Magercise 1

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.