Печать средствами AWT
Листинг 18.7. Печать средствами AWT
import java.awt.*;
import j ava.awt.event.*;
class PrintTest extends Frame{
PrintTest(String s){
super(s);
setSize(400, 400);
setVisible(true);
}
public void simplePrint{){
PrintJob pj =
getToolkitO.getPrintJob(this, "JobTitle", null);
if (pj != null){
Graphics pg = pj.getGraphics();
if (pg != null){
print(pg);
pg.dispose();
}else System.err.println("Graphics's null");
pj.end();
}else System.err.println("Job's null");
}
public void paint(Graphics g){
g.setFonttnew Font("Serif", Font.ITALIC, 30));
g.setColor(Color.black);
g.drawArcdOO, 100, 200, 200, 0, 360);
g.drawstring("Страница 1", 100, 100);
}
public static void main(String[] args){
PrintTest pt = new PrintTest(" Простой гфимер печати");
pt.simplePrint();
pt.addWindowListener(new WindowAdpter(){
public void windowClosing(WindowEvent ev){
System.exit(0);
}
});
}
}