aspose file tools*
The moose likes Threads and Synchronization and the fly likes printing from an applet toolbar the image displayed in the applet via a thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "printing from an applet toolbar the image displayed in the applet via a thread " Watch "printing from an applet toolbar the image displayed in the applet via a thread " New topic
Author

printing from an applet toolbar the image displayed in the applet via a thread

KangN
Greenhorn

Joined: Sep 19, 2001
Posts: 2
Hi ,
I have a JApplet which displays a tiff image. The applet uses JAI API and Java 2D for printing. I can zoom in . zoom out , invert the image and I am printing the displayed image also .
In the action handler class for the print button , I have made an inner class implementing printable and executing the print function.
I am doing printing via a separate thread as i don't want my action handler class to keep waiting till the image gets printed . The user should be able to manipulate the image after it has clicked on the "ok" of the print dialog, while the image is being printed. This is the reason for printing the image in a separate thread
and the actual printing process is a synchronized method called by the run method of the thread .
If I click on print button twice , one after another , the second image gets printed only after I get a response from the printer that image has been printed as expected (as the print method is synchronized ).
In the action handler class of print , I do not call join on the thread as I do not want it to wait for printing to get over ( printing of a tiff image actually takes a long time ?? )
Is there anyway to make the threads independent of the main applet . Like after firing the print command , if I close the applet and I haven't got a confirmation from the printer, I get a blank page or nothing but i get a response message from printer that printing is done .
Is it essential for a thread to wait till the printer sends a response that printing is over ?
Similarly , If after firing the printing command and without waiting for the confirmation from the printer , I refresh the applet , proper printing does not occur but I get a message from the printer that printing is done .
If i use synchronized method for printing and wait till the printer response from the printer comes without closing or refreshing the applet , printing occurs fine .
Can anyone please tell me what is actually happening and is there a better way to print and that printing occurs after the print command has been fired irrespective of the applet ?
Regards , Navneet
Marcela Blei
Ranch Hand

Joined: Jun 28, 2000
Posts: 477
"KangN",
your name is not valid as per the Javaranch name conventions. Please refer to the document located here
 
jQuery in Action, 2nd edition
 
subject: printing from an applet toolbar the image displayed in the applet via a thread