|
|
|
Help is available for each task, or you can go straight to
the solution
source code.
Import the Swing text package. The text-handling support classes are all located here. import javax.swing.text.*; Task 2
Create an instance variable JTextPane pane; StyledDocument doc; Task 3
Create a
Remember to save the references to the doc = new DefaultStyledDocument(); pane = new JTextPane (doc); JScrollPane sp = new JScrollPane (pane); c.add(sp, BorderLayout.CENTER); Task 4
The "Load Text" menu item under the File menu calls the
To clear out the current document, create a new document:pane.setStyledDocument ( doc = new DefaultStyledDocument()); Task 5
For the Color menu, add a
The
At the appropriate location in the source, add the following lines:item.setIcon (new ColoredBox(Color.red)); ... item.setIcon (new ColoredBox(Color.orange)); ... item.setIcon (new ColoredBox(Color.yellow)); ... item.setIcon (new ColoredBox(Color.green)); ... item.setIcon (new ColoredBox(Color.blue)); ... item.setIcon (new ColoredBox(Color.magenta)); Task 6
For each of the color menu items, add an
The
At the appropriate location in the source, add the following lines:item.addActionListener (new StyledEditorKit.ForegroundAction ( "set-foreground-red", Color.red)); ... item.addActionListener (new StyledEditorKit.ForegroundAction ( "set-foreground-orange", Color.orange)); ... item.addActionListener (new StyledEditorKit.ForegroundAction ( "set-foreground-yellow", Color.yellow)); ... item.addActionListener (new StyledEditorKit.ForegroundAction ( "set-foreground-green", Color.green)); ... item.addActionListener (new StyledEditorKit.ForegroundAction ( "set-foreground-blue", Color.blue)); ... item.addActionListener (new StyledEditorKit.ForegroundAction ( "set-foreground-magenta", Color.magenta)); Task 7
For the Custom Color menu item, you need to complete the
Pick a default color to use as the last parameter to Task 8
Most of the Font change support menu is already done for you. The only two
menu items that need action listeners are the Bold and Italic entries. Add
an
Like the
Be sure to check how the font size and family change, too. Task 9
For the Image File menu item, you need to complete the
Use Task 10Save everything and compile the program. Then run it to see the results. Load a file and change its display style. You can save the document and reload the document as a serializable object. Also, try to add an image to the document. javac Formatter.java java Formatter Return to Magercise 3Copyright © 1998-1999 MageLang Institute. All Rights Reserved. |
|
|||
|
|
Questions?
29-Mar-99 Copyright © 1996-1999 Sun Microsystems Inc. All Rights Reserved. Legal Terms. Privacy Policy. |
|