-
Bug
-
Resolution: Duplicate
-
P5
-
None
-
1.1.1
-
None
-
x86
-
windows_nt
Name: joT67522 Date: 09/23/97
All I wish to do is print out some text information held in
a class definition to the printer i.e. a simple report.
I was having problems printing text strings to a printer in
an application that I am writing. Hence I took your example
from the web (below) and it worked OK.
I then added some text printer output lines (See #1) and re-ran it OK.
I then commented the lines for the PrintCanvas (See #2) and the
test fails with :
'The instruction at 0x01abcb28 referenced memory at 0x00000000'
Tests seem to indicate that if the paint method of PrintCanvas
is called PRIOR to printing the string, then there is no
problem. However if it is called afterwards, or not at all then
the application crashes.
Am I doing something really stupid or is this a bug ?
Thnaking you in advance
Keith
import java.awt.*;
import java.awt.event.*;
public class PrintingTest extends Frame implements ActionListener {
PrintCanvas canvas;
public PrintingTest() {
super("Printing Test");
canvas = new PrintCanvas(); #2
add("Center", canvas); #2
Button b = new Button("Print");
b.setActionCommand("print");
b.addActionListener(this);
add("South", b);
pack();
}
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if (cmd.equals("print")) {
PrintJob pjob = getToolkit().getPrintJob(this,
"Printing Test", null);
if (pjob != null) {
Graphics pg = pjob.getGraphics();
if (pg != null) {
canvas.printAll(pg); #2
pg.drawString("Hello There", 20,20); #1
pg.drawString("Hello There1", 20,40); #1
pg.dispose(); // flush page
}
pjob.end();
}
}
}
public static void main(String args[]) {
PrintingTest test = new PrintingTest();
test.show();
}
}
class PrintCanvas extends Canvas {
public Dimension getPreferredSize() {
return new Dimension(100, 100);
}
public void paint(Graphics g) {
System.out.println("PrintCanvas::paint");
Rectangle r = getBounds();
g.setColor(Color.yellow);
g.fillRect(0, 0, r.width, r.height);
g.setColor(Color.blue);
g.drawLine(0, 0, r.width, r.height);
g.setColor(Color.red);
g.drawLine(0, r.height, r.width, 0);
}
}
company - Syntegra Ltd, England, UK , email - ###@###.###
======================================================================
- duplicates
-
JDK-4084038 Win32 printing: Frequent crashes, page scaled down
-
- Closed
-