In this magercise, you will explore the BoxLayout and
Box classes. Here, you'll create two boxes:
- A vertical box with two buttons at opposite extremes
- A horizontal box with 3 buttons evenly spaced across the area,
except that 5 pixels must be unused on the right edge.
The skeleton code preloads the Icon variables rightB ,
leftB , and animB with the icon files.
Magercise 7 Prerequisites
Buttons With Icons
Skeleton Code
BLayout.java
Resources
Tasks
-
Create a vertical box (a
JPanel with a
LayoutManager of BoxLayout )
using the Box class.
-
Create and add two
JButton s with icons rightB and
leftB . Put "glue" between the buttons to push the buttons
to opposite extremes.
-
Create a horizontal box using the
Box class.
-
Create and add three
JButton s with icons rightB ,
leftB , and animB . Put "glue" between
the three buttons. Also, reserve five pixels of space on the right
border with a horizontal strut.
-
Add the two boxes to the frame. The vertical box goes in the west
quadrant, while the horizontal one goes in the center.
-
Save everything and compile the program. Then run it to see the
results. When you resize the screen, you'll notice how the button
positions aren't fixed, but more of a relative position.
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.
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.
|