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
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.
Starting with the skeleton code, import the swing 
package.
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.
Create top and bottom JButtons with 
action event listeners that print "top" and "bottom" to 
standard output.
Create a JLabel with text "Swing Components are like 
AWT 1.1". Add it to the first row of the grid.
Add the top and bottom button to the grid.
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]](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.
Copyright © 1998-1999 
MageLang Institute.
All Rights Reserved.