有没有有关 Java 套打的资料或代码???谢谢~~~~~~~~~~~ 有没有有关 Java 套打的资料或代码???谢谢~~~~~~~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); } }} lifeis,谢谢你,不好意思,你这个程序是怎么运行的~~~~~~~~~ java 泛型怎么那么奇怪? 求指点 Java桌面程序安装部署方案 方法 有地址吗 部署在服务器的程序运行一段时间后,java.exe占用CPU资源比较多,从何着手解决?是否与内存泄漏有关? 封装 请教关于泛型与类型转换 能否提供一个Socket发送和接受XML文件的例子呢?谢谢!! (关于计算日期的类)请大虾帮忙解围,十分感激! 初学,运行java核心技术一书中的代码,出了点问题。向大家请教! JScrollPane的滚动条新玩法 [绝对高分]如何抓取网页内的数据? 在java Swing中,如何在JSplitPane中固定分隔线?
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();
}
}
}