📄 singleprint.java
字号:
package drawfigure.print;
import java.awt.*;
import java.awt.print.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class SinglePrint
implements Printable {
Component myComponent;
public SinglePrint(Component component)
{
this.myComponent = component;
}
public int print(Graphics g, PageFormat pf, int pageIndex)
throws PrinterException
{
if (pageIndex > 1) {
return Printable.NO_SUCH_PAGE;
}
else {
Graphics2D g2 = (Graphics2D) g;
double scale = 1;
double sc1 = pf.getImageableWidth() / myComponent.getWidth();
double sc2 = pf.getImageableHeight() / myComponent.getHeight();
double sc = Math.min(sc1, sc2);
if (sc < 1) {
scale = sc;
}
g2.translate(pf.getImageableX(), pf.getImageableY());
g2.scale(scale, scale);
this.myComponent.paint(g2);
return Printable.PAGE_EXISTS;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -