I want to print a Canvas with a picture (gif) directly from a frame.
So I use a Printjob, but it does not work on both of my linux-systems.
After the frame Print Dialog, I get a frame "Print Error" with
the message : Could not execute pring command (L_java.lang.String...)
If I write the output to a file and pipe it into lpr it works, but it
is no solution.

I append the Java-Source Krankenschein_Test.java
I hope someone can help me!

 
Reinhard Simon

HTL Wr. Neustadt Abt. EDVO  email: [EMAIL PROTECTED]
import java.awt.*;
import java.awt.event.*;

public class Krankenschein_Test extends Frame
   implements ActionListener {
     Frame frame = null;
     private Canvas canvas = null;
     Image image = null;
     private Toolkit toolkit = null;
     private MediaTracker tracker = null;
     public static void main (String[] args ) {
       new Krankenschein_Test();
     }
     public Krankenschein_Test() {
       super ("Printing Willi");
       this.tracker = new MediaTracker (this);
       this.frame = this;
       this.toolkit = getToolkit();
       try {
         this.image = toolkit.getImage("kschein.gif");
         tracker.addImage (image, 0);
         tracker.waitForID (0);
       }
       catch (InterruptedException is) {
         System.out.println ("Fehler beim Laden!");
         System.exit (0);
       }
       setLayout (new BorderLayout ());
       addWindowListener (
         new WindowAdapter () {
           public void windowClosing (WindowEvent e) {
             Runtime.getRuntime().exit(0);
           }
         }
       );
       Button button = new Button ("Drucken");
       button.addActionListener (this);
       add ("South", button);
       add ("Center", canvas = new Canvas () {
         public void paint (Graphics g) {
           g.drawImage (image, 0, 0,frame);
         }
         public Dimension getPreferredSize () {
           return new Dimension (100, 80);
         }
       });
       pack();
       show ();
     }
     public void actionPerformed( ActionEvent e) {
       PrintJob printJob = toolkit.getPrintJob (this, "Printing Willi", null);
       if (printJob != null) {
         Graphics printGraphics = printJob.getGraphics ();
         if (printGraphics != null) {
           frame.printComponents(printGraphics);
//           canvas.printAll (printGraphics);
           printGraphics.dispose();
         }
         else System.out.println ("No PrintGraphics");
         printJob.end();
       }
       else System.out.println ("No PrintJob");
     }
}

GIF image

Reply via email to