Chapter 15


Chapter 14

1. 

What is double-buffering?

image from book

2. 

Where should you place custom painting code in an AWT component?

image from book

3. 

Where should you place custom painting code in a Swing component?

image from book

4. 

Explain what a Swing component’s paint method does.

image from book

5. 

Compare and contrast the use of Component.paint with the use of the Component.repaint methods.

image from book

6. 

What is Separable Model Architecture and what are its benefits?

image from book

7. 

What is a faux-composite component?

image from book

8. 

What is a renderer and which Swing faux-composite components use them?

image from book

9. 

What is an editor and which Swing faux-composite components use them?

image from book

10. 

What are the three categories of Graphics methods?

image from book

11. 

What is the difference between the Graphics and the Graphics2D classes?

image from book

12. 

How can one obtain a reference to a Graphics2D object?

image from book

Answers

1. 

- Double-buffering is the practice of drawing into an offscreen graphics and then copying the resulting image into an onscreen graphics.

2. 

- For AWT components, you should override the component’s paint() method and place your custom drawing instructions inside the overridden method body.

3. 

- The method you should override when painting into a Swing component is paintComponent() which may be considered the Swing counterpart to an AWT component’s paint() method.

4. 

- A Swing component's paint() method calls three methods: paintComponent(), paintBorder() and paintChil-dren(). First, paintComponent() fills the component with its background color unless the component is transparent (see Component.setOpaque() and Component.isOpaque()), and then performs whatever custom painting is appropriate to the component. Then, paintBorder() paints whatever border the component may have (see JComponent.setBor-der()). Finally, paintChildren() calls Component.paint() on all the component’s children.

5. 

- Component.paint() actually performs the painting of a component. The repaint() methods only cause the AWT/ Swing painting framework to schedule a component to be painted.

6. 

- Swing’s separable model architecture creates a loose coupling between components and the data they represent by defining interfaces with which the components interact. The component maintains view functionality but delegates data management to a data model Object. This frees an application to manage its data as it wishes. So long as the data is wrapped in the appropriate data model interface, the component is automatically notified of changes in the data without any special effort on the part of the programmer.

One of the differences between AWT’s and Swing’s approaches to GUI architecture is that Swing employs a separable model architecture while the AWT does not. The difference between Swing’s JList and AWT’s List is a prime example of this. It maintains view functionality but delegates data management to a separate Object, a ListModel. Swing’s separable model architecture creates a loose coupling between Components and the data they represent by defining interfaces with which the Components interact, thus freeing an application to manage its data as it wishes. So long as the data is wrapped in the appropriate interface, the Component is automatically notified of changes in the data without any special effort on the part of the programmer.

7. 

- Faux-composite components create the illusion of having thousands or more children components without incurring the overhead necessary to maintain that many components. Faux-composite components use an object called a renderer to paint the component images or cells.

8. 

- A renderer implements a method that accepts several parameters detailing which cell is about to be painted (the object it represents, whether it’s selected, etc.) and returns a component configured to represent that cell. When the faux-composite component needs to paint itself, it paints each visible cell one at a time by getting this component from the renderer and painting its image at the cell’s location. JList, JTable, JTree and JComboBox use renderers.

9. 

- An editor implements a method that accepts several parameters detailing which cell is about to be edited (the object it represents, whether it’s selected, etc.) and returns a component configured to edit that cell. An editor is similar to a renderer, and greatly simplifies editing a faux-composite component’s underlying data model. JTable, JTree and JComboBox use editors.

10. 

- The three categories of Graphics methods are drawing operations, property-related methods and miscellaneous methods.

11. 

- Graphics2D extends Graphics to provide an additional set of advanced graphics tools such as transparency, anti-aliasing, texture and gradients, as well as more sophisticated control over geometry, coordinate transformations, color management, and text layout.

12. 

- Although the API doesn’t explicitly state it, the Graphics object parameter passed to paint, paintComponent, paintBorder and paintChildren is an instance of Graphics2D.




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