• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

print applet

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to print applet using the printer. If yes, how?
I have a button on my applet. When the user clicks on that button, the applet should be printed. My applet is not signed.
Thanks
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public void printPage() {
try{
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.pageDialog(printJob.defaultPage());
printJob.setPrintable(this, printJob.defaultPage());
if(printJob.printDialog()){
printJob.print();
}
return;
}
catch(PrinterException pe) {
EuamAppletLogger.error(pe, "Exception Caught");
}
}

/**
* Prints the page at the specified index into the specified Graphics context in the specified format.
*
* @param g
* @param pg
* @param page
*
* @return int
*/
public int print(Graphics g, PageFormat pg, int page) throws PrinterException {
Graphics2D g2 = (Graphics2D) g;
if (page >= 1)
return Printable.NO_SUCH_PAGE;
g2.translate(pg.getImageableX(), pg.getImageableY());
paint (g2);
System.gc();
return PAGE_EXISTS;
}
this code pops-up 'An applet would like to print. Do you want to continue?' but the browser just hungs there. I am not able to click on yes/no option. Any thought?
Thanks
 
Saloon Keeper
Posts: 26291
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two words:
Java Sandbox
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So Tim, I can not print java applets on an browser? There must be some way we can print the applet.
Any utility which converts applet to html? basically, I have jtree in applet which is to be printed. Any suggestions on how to print the jtree?
 
Tim Holloway
Saloon Keeper
Posts: 26291
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no simple correspondence between an applet's contents and HTML so it can't be converted. An applet can be made to print, however - it's just that the applet has to be signed. This is a security precaution so that rogue applets that print obscene pictures on 3700 pages can't be let loose indiscriminantly on the Internet.
A common alternative is to send the data that you want back to the server that the applet loaded from and have a servlet or JSP construct a printable page either in HTML or PDF form. That page can then be printed via the browser File/Print menu command. This isn't quite as convenient as printing straight from the applet, but sometimes you can format better and there's no need to sign the applet.
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic