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

huaronghu 2002-07-05 02:11:12
有没有有关 Java 套打的资料或代码???谢谢~~~~~~~~~~~
...全文
176 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
怎么用啊??
lifeis 2002-07-08
  • 打赏
  • 举报
回复
thanx
lifeis 2002-07-08
  • 打赏
  • 举报
回复
都只是关注,没有人给分,真让我伤心
呵呵
daehappy 2002-07-07
  • 打赏
  • 举报
回复
up!gz!
ljlfcy 2002-07-05
  • 打赏
  • 举报
回复
我也up!感谢您
松耦合紧内聚 2002-07-05
  • 打赏
  • 举报
回复
thank
whatyayaya 2002-07-05
  • 打赏
  • 举报
回复
new printProcess().print();
Wonny 2002-07-05
  • 打赏
  • 举报
回复
不好意思,我将来也需要,所以在这里留一句
huaronghu 2002-07-05
  • 打赏
  • 举报
回复
lifeis,谢谢你,不好意思,你这个程序是怎么运行的~~~~~~~~~
lifeis 2002-07-05
  • 打赏
  • 举报
回复
这是在A4上左3厘米,上3厘米处打印一个串,
用户设置的纸张可以从设置对话框获得
lifeis 2002-07-05
  • 打赏
  • 举报
回复
这是一个在A4上的左3厘米,上3厘米处打印出一个字符串,够套打了吧。
至于纸张格式是可以从用户设置对话框得到的。
给分吧,绝对成功
lifeis 2002-07-05
  • 打赏
  • 举报
回复
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();
}
}


}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧