Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/PrintJob/PrintArcTest/PrintArcTest.java
38828 views
/*1* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@bug 410560926@summary Test printing of drawArc preceded by drawString27@author robi.khan28*/2930import java.awt.*;31import java.awt.event.*;3233public class PrintArcTest extends Panel implements ActionListener {34PrintCanvas canvas;3536public PrintArcTest () {37setLayout(new BorderLayout());38canvas = new PrintCanvas ();39add("North", canvas);4041Button b = new Button("Click Me to Print!");42b.setActionCommand ("print");43b.addActionListener (this);44add("South", b);45validate();46}474849public void actionPerformed(ActionEvent e) {50String cmd = e.getActionCommand();51if (cmd.equals("print")) {52PrintJob pjob = getToolkit().getPrintJob(getFrame(), "Printing Test", null);53if (pjob != null) {54Graphics pg = pjob.getGraphics();5556if (pg != null) {57canvas.printAll(pg);58pg.dispose(); //flush page59}60pjob.end();61}62}63}6465private Frame getFrame() {66Container cont = getParent();;6768while ( !(cont instanceof Frame ) ) {69cont = cont.getParent();70}7172return (Frame)cont;73}7475public static void main(String args[]) {76PrintArcTest test = new PrintArcTest();77Frame f = new Frame( "PrintArcTest for Bug #4105609");78f.add( test );79f.setSize(500,400);80f.show();81f.addWindowListener( new WindowAdapter() {82public void windowClosing(WindowEvent ev) {83System.exit(0);84}85}86);87}88}8990class PrintCanvas extends Canvas {91public Dimension getPreferredSize() {92return new Dimension(300,300);93}9495public void paint (Graphics g) {96g.drawString("drawArc(25,50,150,100,45,90);",25,25);97g.drawArc(25,50,150,100,45,90);9899g.drawString("drawOval(25,200,200,40);",25,175);100g.drawOval(25,200,200,40);101102g.dispose();103}104}105106107