can anyone tell me how here the count of st is incrementing like this 2,4,6,8,10 and not like 1,2,3,4,5
how could i get the count of st to increment as 1,2,3,4,5
PrinterJob printJob = PrinterJob.getPrinterJob();
Book book = new Book();
for(int i=0;i<5;i++)
{
book.append(new IntroPage(), printJob.defaultPage());
}
IntroPage class is given below
private final static int POINTS_PER_INCH = 72;
private class IntroPage implements Printable
{
@Override
public int print(Graphics g, PageFormat pageFormat, int page)
{
[B]st++;[/B]
//--- Create the Graphics2D object
Graphics2D g2d = (Graphics2D) g;
//--- Translate the origin to 0,0 for the top left corner
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
//--- Set the default drawing color to black
g2d.setPaint(Color.black);
//--- Draw a border arround the page
Rectangle2D.Double border = new Rectangle2D.Double(0, 0, pageFormat.getImageableWidth(), pageFormat.getImageableHeight());
g2d.draw(border);
//--- Print the title
[B]String titleText = "Printing in Java Part "+st+", Example 4";[/B]
Font titleFont = new Font("helvetica", Font.BOLD, 18);
g2d.setFont(titleFont);
//--- Compute the horizontal center of the page
FontMetrics fontMetrics = g2d.getFontMetrics();
double titleX = (pageFormat.getImageableWidth() / 2)- (fontMetrics.stringWidth(titleText) / 2);
double titleY = 3 * POINTS_PER_INCH;
g2d.drawString(titleText, (int) titleX, (int) titleY);
return (PAGE_EXISTS);
}
}