-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.1, 1.1.4, 1.1.6
-
generic, x86
-
solaris_2.5, windows_95, windows_nt
Name: mc57594 Date: 03/13/97
run the following java application with an
available image; it will not print this image
import java.awt.*;
import java.awt.event.*;
public class PrintingTest extends Frame implements ActionListener {
PrintFrame printFrame;
public PrintingTest( ) {
super( "Printing Test" );
Button b = new Button( "Print" );
b.setActionCommand( "print" );
b.addActionListener( this );
add( "South", b );
pack( );
// create the new PrintFrame
printFrame = new PrintFrame( );
// add WindowListener to perform
// an action on closing this window
addWindowListener( new MyWindowAdapter( ) );
}
public void actionPerformed( ActionEvent e ) {
String cmd = e.getActionCommand();
if ( cmd.equals( "print" ) ) {
handlePrinting();
}
}
public void handlePrinting() {
Dimension dim = new Dimension( 794 - 50, 1123 - 40 );
//printFrame.show( );
printFrame.printCanvas.setSize( dim );
printFrame.printCanvas.repaint( );
// get a new print job and display
// the print dialog
PrintJob pjob = getToolkit( ).getPrintJob( printFrame,
"Printing Test", null );
if (pjob != null) {
Graphics pg = pjob.getGraphics();
if (pg != null) {
printFrame.printCanvas.printAll( pg );
// send the page to printer
pg.dispose();
}
pjob.end();
}
}
public static void main(String args[]) {
PrintingTest test = new PrintingTest();
test.show();
}
}
class PrintFrame extends Frame {
PrintCanvas printCanvas;
public PrintFrame()
{
// create a print frame with
// a canvas in it; all printing
// will take place in this canvas
super("PrintFrame (invisible)");
printCanvas = new PrintCanvas();
add( "Center", printCanvas );
pack();
}
}
class PrintCanvas extends Canvas {
public Dimension getPreferredSize() {
// some magic numbers to print to A4 :-)
return new Dimension(794 - 50, 1123 - 40);
}
// everything that should be printed
// has to be put in this paint method
public void paint(Graphics g) {
Rectangle r = getBounds();
String s = "Java printing at work...";
String lo = "links oben";
String di = "width = " + r.width + " height = " + r.height;
String ro = "rechts oben";
String lu = "links unten";
String ru = "rechts unten";
// set default color
g.setColor( Color.black );
// rectangle around the printable area
g.drawRect( 0, 0, r.width, r.height);
// draw some strings do demonstrate the ability
// to position exactly to pixels
g.drawString(s,
( r.width - g.getFontMetrics().stringWidth( s ) ) / 2,
( r.height + g.getFontMetrics().getHeight( ) ) / 2 );
g.drawString( lo, 1, g.getFontMetrics().getHeight( ) );
g.drawString( di,
( r.width - g.getFontMetrics().stringWidth( di ) ) / 2,
g.getFontMetrics().getHeight( ) );
g.drawString( ro,
r.width - g.getFontMetrics().stringWidth( ro ) - 1,
g.getFontMetrics().getHeight( ) );
g.drawString( lu, 1, r.height );
g.drawString( ru,
r.width - g.getFontMetrics().stringWidth( ru ) - 1,
r.height );
// set a new font
g.setFont( new Font( "SansSerif", Font.PLAIN, 24 ) );
g.drawString(s,
( r.width - g.getFontMetrics().stringWidth( s ) ) / 2,
( r.height + g.getFontMetrics().getHeight( ) ) / 2 + 40 );
// set a new font
g.setFont( new Font( "SansSerif", Font.BOLD + Font.ITALIC, 24 ) );
g.drawString( s,
( r.width - g.getFontMetrics().stringWidth( s ) ) / 2,
( r.height + g.getFontMetrics().getHeight( ) ) / 2 + 80 );
// draw an image: doesn't work with this version of JDK 1.1 !!
Image img = getToolkit().getImage( "logo.gif" );
g.drawImage( img, 1, 30, this );
}
}
class MyWindowAdapter extends WindowAdapter {
public void windowClosing( WindowEvent evt ) {
// exit this application
System.exit( 0 );
}
}
company - INNOSOFT GmbH , email - ###@###.###
======================================================================
- duplicates
-
JDK-4024821 only part of datasheet.html prints
-
- Closed
-