Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to check the status of the printer

891682Oct 20 2012 — edited Oct 22 2012
Hi ,
I am trying to define when:
- the file is printed correctly
- the print job is canceled
- the print job has failed
- the printer require attention (e.g. needs paper)
but i run the application then always output is printDataTransferCompleted,printJobCompleted and no other method is calling.
and another problem is without Listner Print method is working fine but when i m using listner then it wont work.

PrintJobManagment(DocPrintJob job) {
// Add a listener to the print job
job.addPrintJobListener(new PrintJobAdapter() {

public void printDataTransferCompleted(PrintJobEvent pje) {
// The print data has been transferred to the print service
System.out.println("-> 1");
}

public void printJobCanceled(PrintJobEvent pje) {
// The print job was cancelled
System.out.println("-> 2");
setStatus(2);
}

public void printJobCompleted(PrintJobEvent pje) {
// The print job was completed
System.out.println("-> 3");
setStatus(3);
}

public void printJobFailed(PrintJobEvent pje) {
// The print job has failed
System.out.println("-> 4");
setStatus(4);
}

public void printJobNoMoreEvents(PrintJobEvent pje) {
// No more events will be delivered from this
// print service for this print job.
// This event is fired in cases where the print service
// is not able to determine when the job completes.
System.out.println("-> 5");
setStatus(5);
}

public void printJobRequiresAttention(PrintJobEvent pje) {
// The print service requires some attention to repair
// some problem.
// Example: running out of paper would cause this event
// to be fired.
System.out.println("-> 6");
setStatus(6);
}

void setStatus(int iStatus) {
synchronized (PrintJobManagment.this) {
iResult = iStatus;
System.out.println("IRESULT: " + iStatus);
PrintJobManagment.this.notify();
}
}

});
}

/*
* This method is used to wait until the job has an event that will terminate it.
*/
public synchronized int waitForDone() {
try {
// If no event were executed or if only the data transfert event were
// launched executed or if the canceled job event were launched there
// is nothing to be done.
while (iResult==0)
wait();

} catch (InterruptedException e) {
}
return iResult;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 19 2012
Added on Oct 20 2012
2 comments
320 views