-
Bug
-
Resolution: Fixed
-
P4
-
1.1.5, 1.1.8_003, 1.3.0
-
1.4
-
x86
-
windows_95, windows_nt
Name: joT67522 Date: 12/12/97
I've found PrintJob in v1.1.5 to be buggier
than the one in v1.1.4. For example:
(1) it won't print a simple Frame with 3 Buttons
correctly.
(2) it won't print a Canvas at all (gives a
Java.Lang.NullPointerException).
Please run the following program:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class MainFrame extends Frame implements ActionListener
{
Button printWindowButton = new Button("PrintWindow");
Button printCanvasButton = new Button("PrintCanvas");
Button exitButton = new Button("Exit");
public static void
main (String argv[])
{
new MainFrame ();
}
public
MainFrame ()
{
super ("PrintTest");
setLayout(new FlowLayout());
add(printWindowButton);
add(printCanvasButton);
add(exitButton);
printWindowButton.addActionListener(this);
printCanvasButton.addActionListener(this);
exitButton.addActionListener(this);
pack();
show();
}
public void
actionPerformed (ActionEvent e)
{
if (e.getSource() == exitButton)
{
setVisible (false);
dispose ();
System.exit (0);
}
else if (e.getSource() == printWindowButton)
{
PrintJob pjob = getToolkit().getPrintJob(this,"PrintWindow",null);
if (pjob == null) return;
Graphics pgraphics = pjob.getGraphics();
if (pgraphics == null) return;
printAll (pgraphics);
pgraphics.dispose();
pjob.end();
}
else if (e.getSource() == printCanvasButton)
{
PrintJob pjob = getToolkit().getPrintJob(this,"PrintCanvas",null);
if (pjob == null) return;
Graphics pgraphics = pjob.getGraphics();
if (pgraphics == null) return;
PrintCanvas pCanvas = new PrintCanvas();
pCanvas.paint(pgraphics);
pgraphics.dispose();
pjob.end();
}
}
}
class PrintCanvas extends Canvas
{
public
PrintCanvas ()
{
super();
}
public void
paint (Graphics g)
{
g.drawString ("Hello Cruel World.", 50, 50);
}
}
(Review ID: 21825)
======================================================================