I'm not able to get the printout.
here is the code
public class Billing extends Frame implements ActionListener,Printable
{
JButton printbtn = new JButton("Print");
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex > 0)
{
return NO_SUCH_PAGE;
}
// User (0,0) is typically outside the
// imageable area, so we must translate
// by the X and Y values in the PageFormat
// to avoid clipping.
Graphics2D g2d = (Graphics2D)graphics;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// Now we perform our rendering
graphics.drawString("Hello world!", 100, 100);
// tell the caller that this page is part
// of the printed document
return PAGE_EXISTS;
// TODO Auto-generated method stub
}
public Billing
(
printbtn.addActionListener(this);
JPanel panel = new JPanel();
panel.setLayout(new MigLayout("debug,fillx,filly", "[]rel:push[]", "[]1[]"));
panel.add(printbtn);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
)
@Override
public void actionPerformed(ActionEvent e)
{
else if (e.getSource().equals(printbtn))
{
System.out.println("You have clicked on Print Button!");
PrinterJob pj = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (pj.printDialog() == true)
{
try
{
pj.print();
}
catch (PrinterException exc)
{
System.out.println(exc);
}
}
System.out.println("Print Job Ends Here!!!!XXXXX!!!!");
}
}