Java by API/java.awt.print/PrinterException
Версия от 17:43, 31 мая 2010; (обсуждение)
catch PrinterException
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.JPanel;
public class MainClass extends JPanel {
public static void main(String[] args) {
try {
PrinterJob pjob = PrinterJob.getPrinterJob();
pjob.setJobName("Graphics Demo Printout");
pjob.setCopies(1);
pjob.setPrintable(new Printable() {
public int print(Graphics pg, PageFormat pf, int pageNum) {
if (pageNum > 0) // we only print one page
return Printable.NO_SUCH_PAGE; // ie., end of job
pg.drawString("www.jexp.ru", 10, 10);
return Printable.PAGE_EXISTS;
}
});
if (pjob.printDialog() == false) // choose printer
return;
pjob.print();
} catch (PrinterException pe) {
pe.printStackTrace();
}
}
}