Java Components

Submitted by: Submitted by

Views: 217

Words: 855

Pages: 4

Category: Science and Technology

Date Submitted: 06/10/2012 09:07 PM

Report This Essay

Chapter 12 GUI Basics

1. java.awt.Component is the root of all Java GUI component classes. A container class such as JFrame is a subclass of Component. JComponent is the root of Swing GUI component classes.

2. The AWT components are heavy weight while the Swing components are lightweight.

3. You use the constructor of the JFrme class to create a frame. Use the setSize method to set the size of the frame. Use the getSize method to find the size of the frame. if the statement frame.setSize(400, 300) and frame.setVisible(true) were swapped in the MyFrameWithComponents class, you have to resize the frame to display the components in the frame. This is because the setVisible(true) statement causes the container to be repainted, but the setSize(400, 300) doesn’t. When you resize the window, all the components are repainted in the frame.

4. You can add a button to a frame.

Answer: True

You can add a frame to a panel.

Answer: False

You can add a panel to a frame.

Answer: True

You can add any number of components to a panel, to a frame, or to an applet.

Answer: True

You can derive a class from JPanel, JFrame, or JApplet.

Answer: True

5. Line 7 created an instance of JFrame. It should be new Test() instead.

6. Component and JComponent are abstract classes, so you cannot create instances from them. The last line is wrong, because you cannot add an object to a container. Only an instance of Component can be added to a container.

7. The layout manager provides a platform-independent way to place components in a GUI interface. The default layout manager for the content pane of a frame is BorderLayout. To add a component to a frame, you have to add it to the content pane of the frame.

8. Using FlowLayout, the components are arranged in the container from left to right in the...