PrintJob class is used for printing in JAVA.
you have to format the things which you need to take printout.
you can draw rectangle,line any graphics object and also string.
you can set Font & Color for that
EX:
PrintJob job = getToolkit().getPrintJob(fr,"PRINT",null);
Graphics g=job.getGraphics();
g.drawRect(50,30,525,775);
g.setFont(new Font("TimesRoman",Font.BOLD,16));
g.drawString("Welcome to JAVA",220,50);
g.drawLine(50,80,50,500);
g.dispose();
job.end();
Here
fr refers frame object.
g.drawRect(xposition,yposition,width,height);
g.drawString("String to print",Xposition,yposition);
g.drawLine(StartX,StartY,EndX,Endy);
output:
This will draw a rectangle... It will be the complete border for A4 sheet.
after that draw "Welcome to JAVA in TimesRoman font with bold.
And draw Line
then it End the print job
Thank you
No comments:
Post a Comment