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 2:
Creating Your First JFC Application

[Help | Solution | API Docs | Short Course | Magercises]

The JavaTM Foundation Classes (JFC) encompass both the Abstract Window Toolkit (AWT) of old and the new Swing components and architecture. The Swing components can be used like AWT components, including 1.1 event handling. In this Magercise, you will setup the environment to compile, then modify, a basic application that displays a label and two buttons. Selecting a button displays a message to the screen.

Magercise 2 Prerequisites

None.

Skeleton Code

FirstAppl.java

Tasks

  1. If you are using JavaTM Development Kit 1.1.x, you need to add the swingall.jar file to your class path to compile your Swing programs. In the Installation magercise, you installed Swing and set the SWINGHOME environment variable to the installation directory. Now, you need to add the archives to the CLASSPATH.

  2. Starting with the skeleton code, import the swing package.

  3. To have the components appear one on top of each other, modify the skeleton's constructor so that it sets the layout to GridLayout with 3 rows and 1 column.

  4. Create top and bottom JButtons with action event listeners that print "top" and "bottom" to standard output.

  5. Create a JLabel with text "Swing Components are like AWT 1.1". Add it to the first row of the grid.

  6. Add the top and bottom button to the grid.

  7. Save everything and compile the program. Then run it to see the results. Clicking a button displays a message to the screen.

    As a precaution, the Save command appends a "1" to the end of the filename you want to save. This can help prevent you from accidently overwriting your source code.

[Result.gif]

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

The following JavaTM source file represents a solution to this Magercise.

Solution

Magercise 3

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.