🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #26259

Impresi�n con JDK 1.2

#26259
From: Mariano Gal�n Mart�n
Date: Wed, 27 Jan 1999 00:00
111 lines
3915 bytes
    Hola a todos:

    �Alguien ha conseguido imprimir texto con el JDK 1.2? Si es as� por
favor decidme como, yo estoy utilizando el ejemplo que viene en el Java
Tutorial de Sun que solo imprime gr�ficos, en cuanto le meto un drawString,
al imprimir(en pantalla sale bien), me sale el siguiente error:

    A nonfractal internal JIT (3.00.078(x)) error 'Structured
Exception(c0000090)' has occurred in:
     'java/awt/font/TextLine.getBounds
()Ljava/awt/geom/Rectangle2DM':Interpreting method.
     Please report this error in detail to
http://java.sun.com/cgi-bin/bugrepor.cgi


   Es un bug del java o estoy haciendo algo mal?

   Ah� va el c�digo:


import java.awt.geom.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.print.PrinterJob;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;

public class ShapesPrint extends JPanel implements Printable, ActionListener
{


    final static Color bg = Color.white;
    final static Color fg = Color.black;
    final static JButton button = new JButton("Print");

    public ShapesPrint() {
 setBackground(bg);
        button.addActionListener(this);
    }

   public void actionPerformed(ActionEvent e) {
        if (e.getSource() instanceof JButton)

        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(this);
        if (printJob.printDialog()) {
            try {
                printJob.print();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
 }
}
    public void paintComponent(Graphics g) {
 super.paintComponent(g);
 Graphics2D g2 = (Graphics2D) g;
 drawShapes(g2);
}
public void drawShapes(Graphics2D g2){

        Color fg3D = Color.lightGray;

        g2.setPaint(fg3D);
        g2.drawRect(80, 80, 400 - 1, 310);
     ... // dibuja una serie de rect�gulos, elipses, l�neas, etc.

        g2.drawString("hola",10,10); // Esto es lo que provoca el error en
pantalla sale bien, pero al darle a imprimir sale el mensaje anterior.
    }


    public int print(Graphics g, PageFormat pf, int pi) throws
PrinterException {
        if (pi >= 1) {
            return Printable.NO_SUCH_PAGE;
 }
 drawShapes((Graphics2D) g);
        return Printable.PAGE_EXISTS;
    }

   public static void main(String s[]){
 WindowListener l = new WindowAdapter() {
  public void windowClosing(WindowEvent e) {System.exit(0);}
  public void windowClosed(WindowEvent e) {System.exit(0);}
 };
 JFrame f = new JFrame();
 f.addWindowListener(l);
 JPanel panel = new JPanel();
      button.setBounds(10,10,100,100);
 panel.add(button);
 f.getContentPane().add(BorderLayout.SOUTH, panel);
 f.getContentPane().add(BorderLayout.CENTER, new ShapesPrint());
 f.setSize(580, 500);
 f.show();

   }

}

He intentado de todo pero no consigo imprimir texto.
        Podr�a intentar imprimir JLabels pero tambi�n tengo rect�ngulos,
l�neas,etc, como saco todo? Adem�s lo tengo en un JPanel (con lo que debe
implementar el i/f Printable siguiendo la filosof�a  anterior).

    Si alguien tiene alguna idea o conoce alguna direcci�n que me pueda
ayudar que me lo diga, es muy importante.

Muchas gracias.
Technical Details
Message-ID: <78mujd$o9e$1@bufalo.lander.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1116f3,67a977e41a0d1bfb,start
X-Google-Attributes: gid1116f3,public
From: "Mariano Gal�n Mart�n" <mgm@sdsoftware.es>
Subject: Impresi�n con JDK 1.2
Date: 1999/01/27
Message-ID: <78mujd$o9e$1@bufalo.lander.es>
X-Deja-AN: 437487454
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
X-Complaints-To: abuse@lander.es
X-Trace: bufalo.lander.es 917437869 24878 195.76.47.68 (27 Jan 1999 11:51:09 GMT)
Organization: Lander Internet
NNTP-Posting-Date: 27 Jan 1999 11:51:09 GMT
Newsgroups: es.comp.lenguajes.java