Expert Answers

  1. Write a statement to create a JFrame object with a title of “My GUI Application”.
  1. Given the object you created in question 1,write a statement to specify the window size to be 300 pixels wide and 400 pixels high?
  1. What would you need to do to the object from question 1 to make sure that the application containing the object terminated when the object’s window was closed?
  1. Write a Java statement to make the window associated with the object from question 1 visible.
  1. Explain how a BorderLayout manages its display area.
  1. Explain how a FlowLayout manages its display area.
  1. Write a Java statement to have the object from question 1 manage its display area by dividing it into 3 rows which have 4 columns each.
  1. The frame object from question 1 uses a BorderLayout by default. Write Java statements to create a JTextfield object and place it into the bottom part of the frame object’s window. 
  1. Describe the sequence of steps needed to create 3 labels and place them side by side in the top part of a frame which is using a BorderLayout.
  1. What happens if you add two different button objects to the SOUTH part of a frame using a BorderLayout?

 

 

  1. Write a sequence of statements to create 2 JButton objects, and do what is needed so the two buttons appear one above the other on the left side of the display associated with a frame object which is using a BorderLayout. Create ALL objects required.
  1. What packages would need to be imported for the code from question 11?
  1. Write a Java application to display the following GUI. At this point you are only implementing the display. We are not ready to make the calculator actually do any calculations!

ScreenShot

This program has the following requirements:

  1. The size of the calculator is 250 x 250 pixels.
  2. The background and foreground color of the calculator buttons must alternate in a checker board pattern as shown above. You can choose any pair of colors for your foreground and background colors.
  3. The buttons should have at least 5 pixels of space between them.
  4. The text on the buttons should be SanSerif size 16 and be bold.
  5. Your application should be implemented in a single class. The main method of the class does nothing more than create an object of the class. The constructor of the class creates and displays the GUI. The constructor may call other methods of the class if needed.
  6. The class must inherit from JFrame as the following demonstrates:

publicmyGUI extends JFrame { … }

The extends keyword specifies inheritance. Inside the class you can directly access methods of the JFrame class without specifying an object due to inheritance. So when you want to add something to the frame, simply say

add(someComponent);

You can specify the title of the window in your constructor by simply adding the following line as the first thing in your constructor.

super(“Title of your window!”);

 

14. Write a Java application to display the following GUI. At this point you are only implementing the display.

ScreenShot1 

This program has the following requirements:

  1. The textfield should accommodate 3 characters.
  2. The X and Y labels should be next to the corresponding textfields.

Hint: Put each label and its adjacent text field into a panel, then put both panels into another panel!

  1. The buttons should have 10 pixels horizontal spacing and 5 pixels vertical spacing.
  2. For the layout of the JFrame, use FlowLayout(FlowLayout.CENTER, 10, 5).
  3. Your application should be implemented in a single class. The main method of the class does nothing more than create an object of the class. The constructor of the class creates and displays the GUI. The constructor may call other methods of the class if needed.
  4. Do not use inheritance for this program. Use a JFrame member variable as the main window object for this program.