Sending Print job to Printer Problem

View: New views
1 Messages — Rating Filter:   Alert me  

Sending Print job to Printer Problem

by asherbaig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I have add button Named as "Print" using Crtl+P.But i am unable to
send print job for my offscreen image.I need help i don't know what i
m doing wrong.

Here is the code
// WORKING OF NEW PRINTER
        public void battlePrinterActionPerformed() {
               
                IBattleManager battleManager = manager.getBattleManager();
               
                BattleView battleView =
               
                        manager.getWindowManager().getRobocodeFrame().getBattleView();
//we get the dimensions of battkeView
                //we create an object BufferedImage where swe save
                //the width and Height and color of the image from battleview
               
                Rectangle size = battleView.getBounds();
               
                BufferedImage capture = new BufferedImage((int)size.getWidth(),
               
                                (int)size.getHeight(), BufferedImage.TYPE_INT_RGB);
//We call Graphic class first to capture the graphics and we draw this
image with
                //the battleView Object
               
                Graphics2D g = capture.createGraphics();
               
                g.drawImage(battleView.offscreenImage, 0, 0, null);

               
                try {
                        battleManager.pauseBattle();  // pause the battle
                        PrinterJob job = PrinterJob.getPrinterJob();
                         job.setPrintable((Printable) this);
                         boolean ok = job.printDialog();
                         if (ok) {
                             try {
                                  job.print();
                             } catch (PrinterException ex) {
                            }
                         }
                    }
                finally {
                        battleManager.resumeBattle();//resume the battle
                }
                }
        //end of it