class PrintFrame
extends JFrame
implements ActionListener, Printable,Pageable {
public static final int WIDTH = 600;
public static final int HEIGHT = 450;
PrinterJob pj;
JButton jb = new JButton("打印");
JTextArea jta = new JTextArea(100,100);
JTextField jtf = new JTextField();
Graphics2D g2;
static PageFormat pf;
int page;
public PrintFrame() {
setSize(WIDTH, HEIGHT);
setTitle("打印程序");
Container con = getContentPane();
con.add(jb, BorderLayout.NORTH);
con.add(jtf, BorderLayout.SOUTH);
JScrollPane sp = new JScrollPane(jta);
con.add(jta, BorderLayout.CENTER);
jb.addActionListener(this);
pj = PrinterJob.getPrinterJob();
pf = new PageFormat();
Paper p = pf.getPaper();
p.setImageableArea(10, 10, 500, 500);
pf.setPaper(p);
public PageFormat getPageFormat(int pageIndex){
return pf;
}
public Printable getPrintable(int pageIndex){
return this;
}
public int getNumberOfPages(){
return page;
}
public int print(Graphics g, PageFormat pf, int page) throws
PrinterException {