Activity 6.1 - Constructing a frame with buttons using BorderLayout

Topic

In this activity we display a frame with buttons arranged using BorderLayout, which is the default layout for a JFrame.

Here is a picture of what the frame will look like.

The figure displayed is described in detail in the main text where it lists the attributes of the frame.

Task

The task is to display a frame with the following attributes:

You will need to write a Java class to the following outline:

Imports

AWT and Swing.

Inheritance

Extends JFrame.

Instance variables

Four fields of type JButton to represent the buttons.

Constructor

Takes a single String argument used to set the title of the frame.

Instructions

  1. Select File|New Project Next> and create a new Java application called MyEx6_1. In the New Java Application wizard name the project MyEx6_1 and set the Project Location to C:\M257\Unit 6. Change the name of the Main Class to myex6_1.FrameDemo1Test.

    Screengrab of the New Java Application window


  2. Add a new Java class called FrameDemo1 to the project in the same package. Write the code for this class so that it meets the specification above.
  3. Now complete the main class FrameDemo1Test so it will:
  4. Run the project to test your code.
  5. Our sample solution appears in the Solution file.