Java Reference
In-Depth Information
Fig. 13.34 | Drawing with Java 2D.
If the user selects to draw with a gradient, set the Paint on the DrawPanel to be a gradient of
the two colors chosen by the user. The expression
new GradientPaint( 0 , 0 , color1, 50 , 50 , color2, true ))
creates a GradientPaint that cycles diagonally from the upper-left to the bottom-right every 50 pix-
els. Variables color1 and color2 represent the colors chosen by the user. If the user does not select to
use a gradient, then simply set the Paint on the DrawPanel to be the first Color chosen by the user.
For strokes, if the user chooses a solid line, then create the Stroke with the expression
new BasicStroke(width, BasicStroke.CAP_ROUND , BasicStroke.JOIN_ROUND )
where variable width is the width specified by the user in the line-width text field. If the user
chooses a dashed line, then create the Stroke with the expression
new BasicStroke(width, BasicStroke.CAP_ROUND , BasicStroke.JOIN_ROUND ,
10 , dashes, 0 )
where width again is the width in the line-width field, and dashes is an array with one element
whose value is the length specified in the dash-length field. The Panel and Stroke objects should
be passed to the shape object's constructor when the shape is created in DrawPanel .
Making a Difference
13.32 (Large-Type Displays for People with Low Vision) The accessibility of computers and the
Internet to all people, regardless of disabilities, is becoming more important as these tools play in-
creasing roles in our personal and business lives. According to a recent estimate by the World Health
Organization ( www.who.int/mediacentre/factsheets/fs282/en/ ) , 246 million people worldwide
have low vision. To learn more about low vision, check out the GUI-based low-vision simulation at
www.webaim.org/simulations/lowvision.php . People with low vision might prefer to choose a font
and/or a larger font size when reading electronic documents and web pages. Java has five built-in
“logical” fonts that are guaranteed to be available in any Java implementation, including Serif ,
Sans-serif and Monospaced . Write a GUI application that provides a JTextArea in which the user
can type text. Allow the user to select Serif , Sans-serif or Monospaced from a JComboBox . Provide
a Bold JCheckBox , which, if checked, makes the text bold. Include Increase Font Size and Decrease
Font Size JButton s that allow the user to scale the size of the font up or down, respectively, by one
point at a time. Start with a font size of 18 points. For the purposes of this exercise, set the font size
on the JComboBox , JButton s and JCheckBox to 20 points so that a person with low vision will be able
to read the text on them.
Search WWH ::




Custom Search