asherbaig
2008-12-28 16:17:39 UTC
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
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:Robocode-***@yahoogroups.com
mailto:Robocode-***@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
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
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Robocode/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/Robocode/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:Robocode-***@yahoogroups.com
mailto:Robocode-***@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
Robocode-***@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/