1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/* Listing2601.java */
import java.awt.*;
import java.awt.event.*;
public class Listing2601
extends Frame
{
public static void main(String[] args)
{
Listing2601 wnd = new Listing2601();
}
public Listing2601()
{
super("Drucken");
addWindowListener(new WindowClosingAdapter(true));
setBackground(Color.lightGray);
setSize(400,400);
setVisible(true);
//Ausdruck in 2 Sekunden starten
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
//nichts
}
printTestPage();
}
public void paint(Graphics g)
{
paintGrayBoxes(g, 40, 50);
}
public void printTestPage()
{
PrintJob pjob = getToolkit().getPrintJob(
this,
"Testseite",
null
);
if (pjob != null) {
//Metriken
int pres = pjob.getPageResolution();
int sres = getToolkit().getScreenResolution();
Dimension d2 = new Dimension(
(int)(((21.0 - 2.0) / 2.54) * sres),
(int)(((29.7 - 2.0) / 2.54) * sres)
);
//Ausdruck beginnt
Graphics pg = pjob.getGraphics();
if (pg != null) {
//Rahmen
pg.drawRect(0, 0, d2.width, d2.height);
//Text
pg.setFont(new Font("TimesRoman",Font.PLAIN,24));
pg.drawString("Testseite",40,70);
pg.drawString(
"Druckeraufl�sung : " + pres + " dpi",
40,
100
);
pg.drawString(
"Bildschirmaufl�sung : " + sres + " dpi",
40,
130
);
pg.drawString(
"Seitengr��e : " + d2.width + " * " + d2.height,
40,
160
);
//Graustufenk�stchen
paintGrayBoxes(pg, 40, 200);
//Seite ausgeben
pg.dispose();
}
pjob.end();
}
}
private void paintGrayBoxes(Graphics g, int x, int y)
{
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
int level = 16 * i + j;
g.setColor(Color.black);
g.drawRect(x + 20 * j, y + 20 * i, 20, 20);
g.setColor(new Color(level, level, level));
g.fillRect(x + 1 + 20 * j, y + 1 + 20 * i, 19, 19);
}
}
}
}
|