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".
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.
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.
Joined: Oct 21, 2008
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