参考参考import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.applet.Applet;public class print extends Applet{
  Button printButton = new Button( "Print" );
  public void init(){
    printButton.addActionListener( new PrintListener() );
    add( printButton );
  } 
  class PrintListener implements ActionListener{
    public void actionPerformed( ActionEvent e ){
      PrinterJob pj = PrinterJob.getPrinterJob();
      pj.setPrintable(new ImagePrintable());
      if (pj.printDialog()) {
        try { 
          pj.print(); 
        }catch ( PrinterException pe) {
          System.out.println( "Print when exception " );
        }
      }
    }  
  }
  class ImagePrintable implements Printable{
    public int print(Graphics g, PageFormat pf, int pageIndex) {
      if (pageIndex != 0) return Printable.NO_SUCH_PAGE;
//     在 g 上面画东西,比如g.drawString(..............
      return Printable.PAGE_EXISTS;
    }
  }
  
}