428N/A/*
2362N/A * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
428N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
428N/A *
428N/A * This code is free software; you can redistribute it and/or modify it
428N/A * under the terms of the GNU General Public License version 2 only, as
428N/A * published by the Free Software Foundation.
428N/A *
428N/A * This code is distributed in the hope that it will be useful, but WITHOUT
428N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
428N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
428N/A * version 2 for more details (a copy is included in the LICENSE file that
428N/A * accompanied this code).
428N/A *
428N/A * You should have received a copy of the GNU General Public License version
428N/A * 2 along with this work; if not, write to the Free Software Foundation,
428N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
428N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
428N/A */
428N/A/**
428N/A * @test
428N/A * @bug 4257262 6708509
428N/A * @summary Image should be sent to printer.
428N/A* @run main/manual PrintAWTImage
428N/A */
428N/A
428N/Aimport java.awt.*;
428N/Aimport java.awt.event.*;
428N/Aimport java.awt.print.*;
428N/A
428N/A
428N/Apublic class PrintAWTImage extends Frame
428N/A implements ActionListener, Printable {
428N/A
428N/A public Image imgJava;
428N/A
428N/A
428N/A public static void main(String args[]) {
428N/A PrintAWTImage f = new PrintAWTImage();
428N/A f.show();
428N/A }
428N/A
428N/A public PrintAWTImage() {
428N/A
428N/A Button printButton = new Button("Print");
428N/A setLayout(new FlowLayout());
428N/A add(printButton);
428N/A printButton.addActionListener(this);
428N/A
428N/A addWindowListener(new WindowAdapter() {
428N/A public void windowClosing(WindowEvent e) {
428N/A System.exit(0);
428N/A }
428N/A });
428N/A
428N/A pack();
428N/A }
428N/A
428N/A public void actionPerformed(ActionEvent e) {
428N/A
428N/A PrinterJob pj = PrinterJob.getPrinterJob();
428N/A
428N/A if (pj != null && pj.printDialog()) {
428N/A pj.setPrintable(this);
428N/A try {
428N/A pj.print();
428N/A } catch (PrinterException pe) {
428N/A } finally {
428N/A System.err.println("PRINT RETURNED");
428N/A }
428N/A }
428N/A }
428N/A
428N/A
428N/A public int print(Graphics g, PageFormat pgFmt, int pgIndex) {
428N/A if (pgIndex > 0)
428N/A return Printable.NO_SUCH_PAGE;
428N/A
428N/A Graphics2D g2d = (Graphics2D)g;
428N/A g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY());
428N/A Image imgJava = Toolkit.getDefaultToolkit().getImage("duke.gif");
428N/A g2d.drawImage(imgJava, 0, 0, this);
428N/A
428N/A return Printable.PAGE_EXISTS;
428N/A }
428N/A
428N/A}