Activity 6.3 - Simulating a control panel in a lift
Topic
In this activity we build up a more complex window design by nesting several
JPanels in the content pane.
Task
You are asked to write a program that will simulate the control panel in a
lift. Here is a sketch the designer has drawn.

On the content pane there are three panels.
- The top panel holds two text fields, the first to show whether the lift is
travelling up or down, the second to indicate the current floor, and an alarm
button.
- The middle panel contains buttons for the floors.
- The bottom panel contains buttons for opening and closing the doors. (These
just use the < and > characters from the keyboard.)
The design uses a standard title bar, with title "Lift controls".
Notes
The text fields should be four and two characters wide respectively. For
the purposes of this prototype they can just be left blank. To create a
JTextField of the desired width use the constructor
JTextField(int columns)
A JTextField is added to a panel in exactly the same way as we add a JButton.
Instructions
- Create a new project called MyEx6_3 in the Unit 6 folder. In the New Java Application wizard name the Main Class myex6_3.LiftButtonFrameTest.
- Add a new Java class LiftButtonFrame to the project. Complete the coding for this
class so that when an instance of LiftButtonFrame is displayed it will appear as
in the design sketch above.
- Complete the main class LiftButtonFrameTest so it creates a test instance of LiftButtonFrame and makes it visible. Compile and run your
project.
- Our specimen solution can be found in the Solution file.