Java by API/javax.print.event/PrintJobAdapter — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:48, 31 мая 2010
new PrintJobAdapter()
import java.io.FileInputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;
import javax.print.event.PrintJobListener;
public class Main {
public static void main(String args[]) throws Exception {
String filename = args[0];
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
PrintService printService = PrintServiceLookup
.lookupDefaultPrintService();
DocPrintJob job = printService.createPrintJob();
PrintJobListener listener = new PrintJobAdapter() {
public void printDataTransferCompleted(PrintJobEvent e) {
System.out.println("Good-bye");
System.exit(0);
}
};
job.addPrintJobListener(listener);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
}