Java Reference
In-Depth Information
printAll(g2D);
// Draw the component
return PAGE_EXISTS;
Directory "Sketcher 13 printing the application window"
Now you should get the whole application window printed.
SUMMARY
In this chapter you have added full support for the File menu to the Sketcher application for both sketch
storage and retrieval and for printing. You should find that the techniques that you have used here are readily
applicable in other Java applications. The approach to saving and restoring a model object is not usually
dependent on the kind of data it contains. Of course, if your application is a word processor, you have a little
more work to do taking care that the number of lines printed on each page is a whole number of lines. In oth-
er words, you have to make sure you avoid having the top half of a line of text on one page and the bottom
half on the next. There are other Java classes to help with that and I don't really have the space to discuss
them here, but look them up — the javax.swing.text package is a veritable gold mine for text handling!
If you have been following all the way with Sketcher, you now have an application that consists of well
more than 1,500 lines of code, so you should be pretty pleased with yourself. And you're not finished with
Sketcher yet — you add the capability to export and import sketches in XML over the next two chapters.
EXERCISES
You can download the source code for the examples in the topic and the solutions to the following exer-
cises from wrox.com .
1. Modify the Sketcher program to print the title at the top of the page on which the sketch is printed.
2. Modify the printing of a sketch so that a solid black boundary line is drawn around the sketch on
the page.
3. Modify Sketcher to print a single sketch laid out on four pages. The sketch should be enlarged to
provide the best fit on the four pages without distorting circles — that is, the same scale should be
applied to the x and y axes.
4. Use a Book object to print a cover page plus the sketch spread over four pages, as in the previous
exercise.
Search WWH ::




Custom Search