Java Reference
In-Depth Information
Figure 12.1 Display for
the PrintTestApp
program.
and then perform the printing:
...
public class PrintTestApp extends JFrame
implements ActionListener {
...
/** Execute the menu events here. **/
public void actionPerformed (ActionEvent e) {
String command = e.getActionCommand ();
if (command.equals ( " Quit " )) {
dispose ();
System.exit (0);
} else if (command.equals ( " Print " )) {
print ();
}
}
/** Do the print setup up here. **/
public void print () {
PrintJob pjb =
getToolkit ().getPrintJob (this, " Print Test " ,null);
if (pjb! = null) {
Graphics pg = pjob.getGraphics ();
if (pg! = null) {
paint (pg); // Paint all components on this frame.
// flush page when finished
pg.dispose ();
}
pjob.end ();
}
} // print
...
 
Search WWH ::




Custom Search