Java Reference
In-Depth Information
33.
int y=( int )pageFormat.getImageableY() + 1;
34.
g.translate(x,y);
35.
RepaintManager currentManager = RepaintManager.currentManager( this );
36.
currentManager.setDoubleBufferingEnabled( false );
37.
this .paint(g);
38.
currentManager.setDoubleBufferingEnabled( true );
39.
return (PAGE_EXISTS);
40.
}
41. }
42.
43. }
Class PrintFrame generates a frame that has a PrintPanel embedded into its
content pane. The frame has a menu with only one item 'Print'. The listener
for this item is implemented by defining actionPerformed . When the item is
selected, a print job for the embedded panel is generated and started as described
in Section 19.2. The frame also has main method which launches the application.
File: its/Printing/PrintFrame.java
1. package its.Printing;
2.
3. import its.SimpleFrame.SimpleFrame;
4. import java.awt.event.ActionEvent;
5. import java.awt.event.ActionListener;
6. import java.awt.print.PrinterException;
7. import java.awt.print.PrinterJob;
8. import java.awt.BorderLayout;
9. import javax.swing.*;
10.
11. public class PrintFrame extends SimpleFrame
12.
implements ActionListener{
13.
14.
private PrintPanel pp;
15.
16.
public PrintFrame() {
17.
this .setTitle("Printing Application");
18.
pp = new PrintPanel();
19.
this .getContentPane().add(pp,BorderLayout.CENTER);
20.
21.
JMenuBar menuBar = new JMenuBar();
22.
JMenu menu = new JMenu("File");
23.
JMenuItem druckItem = new JMenuItem("Print");
24.
menuBar.add(menu);
25.
menu.add(druckItem);
26.
druckItem.addActionListener( this );
Search WWH ::




Custom Search