Java Reference
In-Depth Information
sponding JTextField . When the user changes the value of the JSlider , the JTextField should be
changed accordingly. Use your new GUI component as part of an application that displays the cur-
rent Color value by drawing a filled rectangle.
22.12 (Creating a Color Chooser: Modification) Modify the MyColorChooser class of Exercise 22.11
to allow the user to enter an integer value into a JTextField to set the red, green or blue value. When
the user presses Enter in the JTextField , the corresponding JSlider should be set to the appropriate
value.
22.13 (Creating a Color Chooser: Modification) Modify the application in Exercise 22.12 to draw
the current color as a rectangle on an instance of a subclass of JPanel which provides its own paint-
Component method to draw the rectangle and provides set methods to set the red, green and blue
values for the current color. When any set method is invoked, the drawing panel should automati-
cally repaint itself.
22.14 (Drawing Application) Modify the application in Exercise 22.13 to allow the user to drag
the mouse across the drawing panel (a subclass of JPanel ) to draw a shape in the current color. En-
able the user to choose what shape to draw.
22.15 (Drawing Application Modification) Modify the application in Exercise 22.14 to allow the
user to terminate the application by clicking the close box on the window that is displayed and by
selecting Exit from a File menu. Use the techniques shown in Fig. 22.5.
22.16 (Complete Drawing Application) Using the techniques developed in this chapter and
Chapter 12, create a complete drawing application. The program should use the GUI components
from Chapter 12 and this chapter to enable the user to select the shape, color and fill characteristics.
Each shape should be stored in an array of MyShape objects, where MyShape is the superclass in your
hierarchy of shape classes. Use a JDesktopPane and JInternalFrame s to allow the user to create mul-
tiple separate drawings in separate child windows. Create the user interface as a separate child win-
dow containing all the GUI components that allow the user to determine the characteristics of the
shape to be drawn. The user can then click in any JInternalFrame to draw the shape.
 
Search WWH ::




Custom Search