Exercises

  • Exercise 11-1. Take a look again at Figure 11-7. Write a class that produces a sample layout like GridBagLayoutPane, without using the GridBagLayout layout manager. You’ll probably want to use BorderLayout and the Box container or BoxLayout layout manager.

  • Exercise 11-2. The ScribblePane class of Example 11-13 draws all of its lines using the foreground property. If this property changes, the color of all lines changes. Modify the class so that it remembers the setting of foreground when each PolyLine was drawn, and uses these retained colors in its paintComponent( ) method. With this modification, changes to the foreground property will not affect the currently displayed lines, only lines subsequently drawn.

  • Exercise 11-3. The ItemChooser class allows items to be specified only when the component is created. Add methods that allow items to be added and removed. Make the methods work regardless of the presentation type in use.

  • Exercise 11-4. The ScribbleApp application defines and uses a ColorAction class to allow the user to select the current drawing color. Add a LineWidthAction class that lets the user select the line width. To accomplish this, give the ScribblePane component a setLineWidth( ) method so that the line width can be varied.

  • Exercise 11-5. One shortcoming of the FontChooser class is that when you call setSelectedFont( ), the ItemChooser components are not updated to match the current font. Modify FontChooser so that it does update these selections. You’ll probably ...

Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.