import java.awt.geom.*;
import java.awt.print.*;
public void actionPerformed(ActionEvent e) {
// Get a PrinterJob
PrinterJob job = PrinterJob.getPrinterJob();
// Create a landscape page format
PageFormat landscape = job.defaultPage();
landscape.setOrientation(PageFormat.LANDSCAPE);
// set up a book
Book bk = new Book();
bk.append(new PaintCover(), job.defaultPage());
bk.append(new PaintContent(), landscape);
// Pass the book to the PrinterJob
job.setPageable(bk);
// Put up the dialog box
if (job.printDialog()) {
// print the job if the user didn't cancel printing
try { job.print(); }
catch (Exception exc) { /* Handle Exception */ }
}
OR TRY THE FULL PROGRAM
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.geom.*;
import java.awt.print.*;
/* <applet code="SimpleBook" height=200 width=200></applet>*/
public class SimpleBook extends JPanel implements ActionListener{
final static Color bg = Color.white;
final static Color fg = Color.black;
final static Color red = Color.red;
final static Color white = Color.white;
final static BasicStroke stroke = new BasicStroke(2.0f);
final static BasicStroke wideStroke = new BasicStroke(8.0f);
final static float dash1[] = {10.0f};
final static BasicStroke dashed = new BasicStroke(1.0f,
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER,
10.0f, dash1,
0.0f);
final static JButton button = new JButton("Print");
public SimpleBook() {
setBackground(bg);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {