RoundedRectTest.java revision 14851:980da45565c8
1/*
2 * Copyright (c) 1998, 2016, 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 * @test
26 * @key headful
27 * @bug 4061440
28 * @summary Checks that rounded rectangles print correctly.
29 * @author dpm
30 */
31
32import java.awt.*;
33import java.awt.event.*;
34
35public class RoundedRectTest {
36    public static void main(String[] args) {
37        new RoundedRectTest().start();
38    }
39    public void start() {
40        new RoundedRectTestFrame();
41    }
42}
43
44class RoundedRectTestFrame extends Frame implements ActionListener {
45    PrintCanvas canvas;
46
47    public RoundedRectTestFrame () {
48        super("RoundedRectTest");
49        canvas = new PrintCanvas ();
50        add("Center", canvas);
51
52        Button b = new Button("Print");
53        b.setActionCommand ("print");
54        b.addActionListener (this);
55        add("South", b);
56
57        pack();
58        setVisible(true);
59    }
60
61
62    public void actionPerformed(ActionEvent e) {
63        String cmd = e.getActionCommand();
64        if (cmd.equals("print")) {
65            PrintJob pjob = getToolkit().getPrintJob(this, "RoundedRectTest",
66                                                     null);
67            if (pjob != null) {
68                Graphics pg = pjob.getGraphics();
69
70                if (pg != null)  {
71                    canvas.printAll(pg);
72                    pg.dispose();  //flush page
73                }
74
75                pjob.end();
76            }
77        }
78    }
79}
80
81class PrintCanvas extends Canvas {
82    public Dimension getPreferredSize() {
83        return new Dimension(659, 792);
84    }
85
86    public void paint (Graphics g) {
87        setBackground(Color.white);
88        g.setColor(Color.blue);
89        g.fillRoundRect(50, 50, 100, 200, 50, 50);
90        g.fillRoundRect(200, 50, 100, 100, 50, 50);
91        g.fillRoundRect(350, 50, 200, 100, 50, 50);
92
93        g.fillRoundRect(50, 300, 100, 200, 41, 97);
94        g.fillRoundRect(200, 300, 100, 100, 41, 97);
95        g.fillRoundRect(350, 300, 200, 100, 41, 97);
96
97        g.fillRoundRect(50, 550, 100, 200, 97, 41);
98        g.fillRoundRect(200, 550, 100, 100, 97, 41);
99        g.fillRoundRect(350, 550, 200, 100, 97, 41);
100    }
101}
102