有没有有关 Java 套打的资料或代码???谢谢~~~~~~~~~~~

解决方案 »

  1.   

    package test;import javax.swing.*;
    import java.awt.print.*;
    import java.awt.Graphics2D;
    import java.awt.Graphics;
    import java.util.Enumeration;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2002</p>
     * <p>Company: </p>
     * @author 
     * @version 1.0
     */public class printProcess  implements Printable
    {
      //private printContents aPrintContents;
      private PageFormat aPageFormat;
      private boolean marginReset;
      private boolean directionReset;
      private double lMargin;
      private double rMargin;
      private double tMargin;
      private double bMargin;
      public printProcess()
      {
        //aPrintContents=new printContents();
        aPageFormat=new PageFormat();
        marginReset=false;
        directionReset=false;
        lMargin=0;
        rMargin=0;
        tMargin=0;
        bMargin=0;  }  public int print(Graphics g,PageFormat pf,int page) throws PrinterException
      {
        if(page>=1) return Printable.NO_SUCH_PAGE;
        Graphics2D g2=(Graphics2D)g;    g2.translate(pf.getImageableX(),pf.getImageableY());    //get printer capabilities by dot
        double xPrinter=pf.getWidth();
        double yPrinter=pf.getHeight();    double xRatio=xPrinter/21;  //21 is the width of the paper
        double yRatio=yPrinter/29.7;//29.7 is the height of the paper
        //Enumeration contentEnum=this.aPrintContents.getContentList().elements();
        //while(contentEnum.hasMoreElements())
        //{
        //  printContent aPrintContent=(printContent)contentEnum.nextElement();
        //  g2.drawString(aPrintContent.getContent(),(int)(aPrintContent.getXPosition()*xRatio),(int)(aPrintContent.getYPosition()*yRatio));
        //}
        g2.drawString("whatyayayaya",(int)(3*xRatio),(int)(3*yRatio));    for(int i=0;i<500;i++)
          g2.drawLine(0,0,i,0);
        for(int j=0;j<500;j++)
          g2.drawLine(0,0,0,j);    return Printable.PAGE_EXISTS;
      }  //public void setObjects(printContents thePrintContents)
      //{
      //  this.aPrintContents=thePrintContents;
      //}  public void setLandscapeOrPortrait(int orient)
      {
        this.aPageFormat.setOrientation(orient);
        this.directionReset=true;
      }  public void setMargin(double leftMargin ,double rightMargin,double topMargin, double bottomMargin)
      {
        this.lMargin=leftMargin;
        this.rMargin=rightMargin;
        this.tMargin=topMargin;
        this.bMargin=bottomMargin;
        this.marginReset=true;
      }  //scheduled by user
      public void print()
      {
        //tell whether there exists sth 2 print
        //if(this.aPrintContents==null)
        //  return;    try
        {
           java.awt.print.PrinterJob job =PrinterJob.getPrinterJob();
           PageFormat pf;       //whether PageFormat is customed set or not
           pf=job.defaultPage();
           if(this.marginReset)
           {
             Paper paper=new Paper();
             double xRatio=pf.getWidth()/21;
             double yRatio=pf.getHeight()/29.7;
             paper.setImageableArea(this.lMargin*xRatio,
                                    this.rMargin*yRatio,
                                    pf.getWidth()-this.rMargin*xRatio-this.lMargin*xRatio,
                                    pf.getHeight()-this.bMargin*yRatio-this.tMargin*yRatio);
             pf.setPaper(paper);
             this.marginReset=false;
           }
           if(this.directionReset)
           {
             pf.setOrientation(this.aPageFormat.getOrientation());
             this.directionReset=false;
           }       //pf.setPaper(this.aPageFormat.getPaper());
           job.setPrintable(this,pf);       if(job.printDialog())
           {
             job.print();
           }
         }
         catch(Exception e)
         {
           e.printStackTrace();
        }
      }
    }
      

  2.   

    lifeis,谢谢你,不好意思,你这个程序是怎么运行的~~~~~~~~~