大家看看这个java什么时候调用的print方法?
先是在外部的class文件里写
clsServletAdmPatientPrint csapp = new clsServletAdmPatientPrint;
csapp.printContent;
然后就是在打印的class文件里面写
public class clsServletAdmPatientPrint implements Printable {
private int PAGES = 0;
public int print(Graphics gp, PageFormat pf, int page) throws PrinterException {
Graphics2D g2 = (Graphics2D) gp;
g2.setPaint(Color.black); //黒色
if (
page >= PAGES)
return Printable.NO_SUCH_PAGE;
Font font = new Font("MS明朝", Font.PLAIN, 7);
g2.setFont(font);
g2.drawString(strDate,150,3);
return Printable.PAGE_EXISTS;
}
//打印内容到指定位置
public void printContent(String strSyohousenNo) throws Unsupported
EncodingException{
strSyohousenNo = strSyohousenNo;
PAGES =1; //指定页数
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = printService.createPrintJob();
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(MediaSizeName.ISO_A4);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(this, flavor, das);
try {
job.print(doc, pras);
} catch (PrintException pe) {
pe.printStackTrace();
}
}
}
小弟有这么两个问题不太清楚,
1。外面只有写调用printContent方法,那
public int print是被自动调用的吗?
2。(
page >= PAGES)这句话中,page什么时候被付值得?
麻烦各位了,谢谢
------解决方案--------------------你发这些代码还真看不出来怎么调用的print
PrintService 是什么
job.print(doc, pras); 又是什么
------解决方案-------------------- try {
job.print(doc, pras);
} catch (PrintExcep