Java Reference
In-Depth Information
You could combine handling the closeAction event with the newAction event by changing the if - else
block for newAction in the definition of actionPerformed() in the FileAction inner class to:
} else if(this == newAction || this == closeAction){
checkForSave();
theApp.insertModel(new SketcherModel()); // Insert new
empty sketch
currentSketchFile = null; // No file for it
setTitle(frameTitle);
sketchChanged = false; // Not changed
yet
return;
} else if(this == printAction) {
Directory "Sketcher 5 checking for save on close and exit"
The Exit menu item terminates the application, so handling the event for this just involves calling check-
ForSave() to make sure the current sketch is not lost inadvertently:
} else if(this == exitAction) {
checkForSave();
System.exit(0);
}
Directory "Sketcher 5 checking for save on close and exit"
All but one of the file menu items are now operable. To complete the set you just need to get printing up
and running.
PRINTING IN JAVA
Printing is always a messy business — inevitably so, because you have to worry about tedious details such
as the size of a page, the margin sizes, and how many pages you're going to need for your output. As you
might expect, there are differences between the process for printing an image and printing text, but the basic
mechanism is the same. You may have the added complication of several printers with different capabilit-
ies being available, so with certain types of documents you need to select an appropriate printer. The way
through this is to take it one step at a time. Let's understand the general principles first.
There are five packages dedicated to supporting printing capabilities in Java:
javax.print : Defines classes and interfaces that enable you to determine what printers are avail-
able and what their capabilities are. It also enables you to identify types of documents to be prin-
ted.
Search WWH ::




Custom Search