1 /*
2  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /**
25  * @bug 4184565
26  * @summary Confirm that the default foreground color on a printer
27  *          graphics object is black so that rendering will appear
28  *          without having to execute setColor first.
29  * @run applet/manual=yesno InitToBlack.html
30  */
31 
32 import java.awt.*;
33 import java.awt.print.*;
34 import java.applet.Applet;
35 
36 public class InitToBlack extends Applet implements Printable {
37 
init()38     public void init() {
39         PrinterJob pjob = PrinterJob.getPrinterJob();
40 
41         Book book = new Book();
42         book.append(this, pjob.defaultPage());
43         pjob.setPageable(book);
44 
45         try {
46             pjob.print();
47         } catch (PrinterException e) {
48             throw new RuntimeException(e.getMessage());
49         }
50     }
51 
print(Graphics g, PageFormat pf, int pageIndex)52     public int print(Graphics g, PageFormat pf, int pageIndex) {
53         Graphics2D g2d = (Graphics2D) g;
54         g2d.translate(pf.getImageableX(), pf.getImageableY());
55 
56         g.drawString("Test Passes", 200, 200);
57 
58         return PAGE_EXISTS;
59     }
60 
main(String[] args)61     public static void main(String[] args) {
62         new InitToBlack().init();
63         System.exit(0);
64     }
65 }
66