Exercises
Exercise 11-1. Take a look again at Figure 11-7. Write a class that produces a sample layout like
GridBagLayoutPane
, without using theGridBagLayout
layout manager. You’ll probably want to useBorderLayout
and theBox
container orBoxLayout
layout manager.Exercise 11-2. The
ScribblePane
class of Example 11-13 draws all of its lines using theforeground
property. If this property changes, the color of all lines changes. Modify the class so that it remembers the setting offoreground
when eachPolyLine
was drawn, and uses these retained colors in itspaintComponent( )
method. With this modification, changes to theforeground
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 aColorAction
class to allow the user to select the current drawing color. Add aLineWidthAction
class that lets the user select the line width. To accomplish this, give theScribblePane
component asetLineWidth( )
method so that the line width can be varied.Exercise 11-5. One shortcoming of the
FontChooser
class is that when you callsetSelectedFont( )
, theItemChooser
components are not updated to match the current font. ModifyFontChooser
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.