• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing the applet screen

 
priya gnana
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to print the applet screen through the printer....Can anyone help me...?I want to know,what should be to print the applet screen?Please help me,out...
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by priya gnana:
i want to print the applet screen through the printer....Can anyone help me...?I want to know,what should be to print the applet screen?Please help me,out...


By "applet screen" I presume you mean the applet being displayed in the browser.

Using the Robot class, you can capture the screen images.
Then you save them as a temp image file.
Then you invoke the printer API to print them to the printer.

Also check out this thread where Ulf has been most helpful (and patient if I may add so)
http://www.coderanch.com/t/259383/Applets/java/Save-applet-page-as-JPG
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applet is a subclass of Component, so you can use its print methods. Using java.awt.print, you can create a Printable object that will print your applet. A naive approach:

I say naive because it will only print the part of the applet that fits on the first page. If your applet is larger you will have to print your component multiple times, but each time a different part. You will probably have to use Graphics.translate for that, to "shift your paper under a different part of your applet".
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to take print of my applet screen(my whole screen).i enabled the print in the popupmenu item at the right click.In My program,on right click ,according to the option the color of the rectangle changes.My problem is,
1. i could not able take the print out for my full applet screen.
2. if the color of the rectangle changes,the print out is getting only for the default color of the rectangle.


please help me....
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Neeba Rebbaca:
1. i could not able take the print out for my full applet screen.

Do you mean that only a small part of your applet is printed? As in, that part that fits on your screen?

If so, you must print multiple pages. For instance:

See how this code will use multiple pages? You just have to fill in the pseudo code (methods with _ in the name), using the page size, component size and current page. For instance, if your applet would need 3 pages vertically and 2 pages horizontally (for a total of 6 pages), then that's what rows and columns should become. row and column are quite easy after that, with just % and / you can easily calculate the row and column of the current page. Page 3 (starting at 0 of course) would have row == 1 and column == 1.
The translating just needs to put the current "page" on the graphics object correctly.

Also, don't create a new PrinterJob - you are already printing, with the settings specified by the user. Just use those.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you explain what 'll the following 'll do...and can you explain what this 'll do?
*calculate_current_column()
* calculate_current_row
* translate_graphics
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
View your applet as a table of pages:

Each cell should fit exactly on one page that is printed.

The first two methods calculate the row number and column number of the page (cell) you are going to print, e.g. 1 and 0. It's most likely something like page / columns and page % columns.

translate_graphics should translate your Graphics object such that the top-left point of the current page in your "table" will be the top-left point of the Graphics object when painting / printing.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic