Chapter 13


Chapter 12

1. 

Explain the difference between the computer screen’s coordinate system and a typical algebraic Cartesian system.

image from book

2. 

What is the difference between LayoutManager2 and LayoutManager?

image from book

3. 

What is the difference between a component and a container?

image from book

4. 

Are Swing components (JComponents) containers? Explain.

image from book

5. 

Which JComponents allow the user to enter text?

image from book

6. 

Which JComponents represent boolean values?

image from book

7. 

Which JComponents allow the user to select from a discrete number of options?

image from book

8. 

What are the three Swing top-level containers and what are their differences?

image from book

9. 

Which layout managers automatically resize the components they contain?

image from book

10. 

List and describe the various fields of the GridBagConstraints object.

image from book

11. 

Why would one use a layout manager?

image from book

12. 

How is a JMenu like a JComboBox?

image from book

13. 

Name two layout managers that layout components based on the order in which they were added to a container.

image from book

14. 

Name two constraints-based layout managers.

 - borderlayout and gridbaglayout are constraints-based layout managers.

Answers

1. 

- The computer screen can be thought of as a 2-dimensional Cartesian coordinate system with horizontal x-axis and vertical y-axis. The origin (x = 0, y = 0) is the top-left corner of the screen. X-axis coordinates increase right-wards and y-axis coordinates increase downwards. The typical algebraic coordinate system has the origin in the center and the y-axis increases upwards.

2. 

- The LayoutManager interface defines methods for laying out components based partly on the order in which they are added to the container. The LayoutManager2 interface extends LayoutManager by adding methods that allow a component to be associated with a constraints object when it is added to a container. This constraints object amounts to a set of suggestions as to how a component should be sized and positioned in the container.

3. 

- A component is an instance or descendant of java.awt.Component and has a visible representation on the screen that may or may not respond to user input. A container is an instance or descendant of java.awt.Container and is nothing more than a component that can “contain” other components.

4. 

- All Swing components except for the top-level Swing containers extend from javax.swing.JComponent which extends from Container. This means that JComponents are containers, and can theoretically be used as such. But we probably shouldn’t use them as containers, since this would be working against their intended purpose. If we need a container to which to add components, we should stick with JPanel.

5. 

- The JComponents that allow a user to enter text include JTextField, JPasswordField and JTextArea.

6. 

- The JComponents that represent boolean values include JToggleButton, JCheckBox and JRadioButton.

7. 

- The JComponents that allow a user to select from a discrete set of options include JComboBox, JList and JMenu.

8. 

- The three top-level Swing containers are:

JWindow which has no borders and no menubar. A JWindow isn’t much more than a rectangular section of screen that has been filled with a default background color and reserved for the use of the application.

JFrame which is usually what we think of when we say “window”. A JFrame typically includes a close-box, a title bar, a border than can be dragged to resize the frame, and an optional menu bar.

JDialog which is typically used to take some form of input from the user. Like a JFrame, it has a title and a border and an optional menubar. A JDialog is very similar to a JFrame except that it is dependent on a parent frame or dia-log. When its parent is hidden or closed, the JDialog is hidden or closed. Also, a JDialog can be modal which means that it can block user input to other parts of the application until it’s closed.

9. 

- GridLayout, BorderLayout and GridBagLayout layout managers automatically resize the components they contain. FlowLayout does not.

10. 

- The gridx and gridy fields are integers that determine the column and row of the top left corner of the component.

The gridwidth and gridheight fields are integers that determine how many columns and rows the component should span.

The fill field is an integer that determines how a component should fill its space if the space allotted to it is larger than its preferred size.

The ipadx and ipady fields are integers that determine the minimum padding to be added to the component’s width and height.

The insets field is an instance of java.awt.Insets and determines how much space there should be on all sides of the component. The insets object has four fields: left, right, top and bottom.

The weightx and weighty fields are floating values ranging from 0.0 to 1.0. If, after all other calculations have been made, the GridBagLayout has calculated the combined area of all the components to be smaller than the con-tainer’s available area, GridBagLayout will distribute the extra space to each row and column according to their respective weightx and weighty values.

The anchor field is an integer that determines where, within its space, a component is positioned.

11. 

- By installing a layout manager into a Container through Container.setLayout() we avoid much of the headache of managing a container’s layout ourselves.

12. 

- A JMenu is like a JComboBox in that it is essentially a button that causes a list of options to pop up.

13. 

- FlowLayout and GridLayout layout components based in the order in which they were added to a container.

14. 

- BorderLayout and GridBagLayout are constraints-based layout managers.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net