本文整理汇总了Java中java.awt.PrintGraphics类的典型用法代码示例。如果您正苦于以下问题:Java PrintGraphics类的具体用法?Java PrintGraphics怎么用?Java PrintGraphics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrintGraphics类属于java.awt包,在下文中一共展示了PrintGraphics类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isPrinting
import java.awt.PrintGraphics; //导入依赖的package包/类
private static boolean isPrinting(Graphics g) {
return g instanceof PrintGraphics || g instanceof PrinterGraphics;
}
示例2: isPrinting
import java.awt.PrintGraphics; //导入依赖的package包/类
private static boolean isPrinting(Graphics g)
/* 113: */ {
/* 114:190 */ return ((g instanceof PrintGraphics)) || ((g instanceof PrinterGraphics));
/* 115: */ }
示例3: printLongString
import java.awt.PrintGraphics; //导入依赖的package包/类
private void printLongString(PrintJob pjob, Graphics pg, String s) {
// Replacing the TABS with spaces
s = Utils.replace(s, "\t", " ");
int margin = 50;
int pageNum = 1;
int linesForThisPage = 0;
int linesForThisJob = 0;
// Note: String is immutable so won't change while printing.
if (!(pg instanceof PrintGraphics)) {
throw new IllegalArgumentException("Graphics context not PrintGraphics");
}
StringReader sr = new StringReader(s);
LineNumberReader lnr = new LineNumberReader(sr);
String nextLine;
int pageHeight = pjob.getPageDimension().height - margin;
Font helv = new Font("Monospaced", Font.PLAIN, 8);
//have to set the font to get any output
pg.setFont(helv);
FontMetrics fm = pg.getFontMetrics(helv);
int fontHeight = fm.getHeight();
int fontDescent = fm.getDescent();
int curHeight = margin;
try {
do {
nextLine = lnr.readLine();
if (nextLine != null) {
if ((curHeight + fontHeight) > pageHeight) {
// New Page
//System.out.println ("" + linesForThisPage + " lines printed for page " + pageNum);
if (linesForThisPage == 0) {
//System.out.println ("Font is too big for pages of this size; aborting...");
break;
}
pageNum++;
linesForThisPage = 0;
pg.dispose();
pg = pjob.getGraphics();
if (pg != null) {
pg.setFont(helv);
}
curHeight = 0;
}
curHeight += fontHeight;
if (pg != null) {
pg.drawString(nextLine, margin, curHeight - fontDescent);
linesForThisPage++;
linesForThisJob++;
} else {
//System.out.println ("pg null");
}
}
} while (nextLine != null);
} catch (EOFException eof) {
// Fine, ignore
} catch (Throwable t) { // Anything else
t.printStackTrace();
}
//System.out.println ("" + linesForThisPage + " lines printed for page " + pageNum);
//System.out.println ("pages printed: " + pageNum);
//System.out.println ("total lines printed: " + linesForThisJob);
}
示例4: isPrinting
import java.awt.PrintGraphics; //导入依赖的package包/类
private static boolean isPrinting(Graphics g)
{
return ((g instanceof PrintGraphics)) || ((g instanceof PrinterGraphics));
}