我有打印字符串的代码,它在程序本身中传递。在这里,我在打印按钮上调用此代码以获取硬拷贝。现在我想用相同的代码打印一个 JForm,但我不知道如何做到这一点。JForm 有一些标签和用户详细信息的文本字段。这是我打印字符串“Hello World”的代码。
public class PrintClass implements Printable, ActionListener {
public int display(Graphics g, PageFormat pf, int page) throws
PrinterException {
if (page > 0) { /* We have only one page, and 'page' is zero-based */
return NO_SUCH_PAGE;
}
/* User (0,0) is typically outside the imageable area, so we must
* translate by the X and Y values in the PageFormat to avoid clipping
*/
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
/* Now we perform our rendering */
g.drawString("Hello World", 100, 100);
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
请帮助我调用 JForm 的构造函数,而不是传递字符串。