1 /* 2 * Copyright (c) 2008, 2018, 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 * 28 * @summary converted from VM Testbase jit/misctests/fpustack. 29 * VM Testbase keywords: [jit, desktop, jdk_desktop, quick] 30 * 31 * @library /vmTestbase 32 * /test/lib 33 * @run driver jdk.test.lib.FileInstaller . . 34 * @run main/othervm jit.misctests.fpustack.GraphApplet 35 */ 36 37 package jit.misctests.fpustack; 38 39 import java.util.*; 40 import java.awt.*; 41 import java.applet.Applet; 42 import nsk.share.TestFailure; 43 44 45 public class GraphApplet extends Applet { 46 private GraphPanel panel; 47 private boolean isApplet = true; 48 private boolean initialized = false; 49 50 /** 51 ** main method for testing that class 52 ** 53 **/ 54 public static void main( String[] args ) { 55 Frame f = new Frame("GraphApplet"); 56 GraphApplet app = new GraphApplet(); 57 app.isApplet = false; 58 app.setSize(600,400); 59 f.setLayout( new BorderLayout() ); 60 f.add("Center",app); 61 f.setSize(600,400); 62 63 app.init(); 64 // f.pack(); 65 f.show(true); 66 app.start(); 67 68 try { 69 Thread.currentThread().sleep(5*1000); 70 } catch (InterruptedException e) { 71 } 72 73 f.show(false); 74 app.stop(); 75 f.dispose(); 76 return; 77 } 78 79 /** 80 ** init-Method in applet's lifecycle. 81 ** the graphic panel is build up and the date is filled. 82 **/ 83 public synchronized void init() { 84 System.out.println( "GraphApplet : init"); 85 setLayout(new BorderLayout()); 86 87 panel = new GraphPanel(this, new layout() ); 88 fill( panel ); 89 add("Center", panel); 90 Panel p = new Panel(); 91 add("South", p); 92 initialized = true; 93 } 94 95 public synchronized void start() { 96 System.out.println( "GraphApplet : start"); 97 panel.formatNodes(); 98 } 99 public synchronized void stop() { 100 initialized = false; 101 System.out.println( "GraphApplet : stop"); 102 } 103 104 public synchronized void destroy() { 105 System.out.println( "GraphApplet : destroy"); 106 } 107 108 /** 109 ** paint the Applet 110 **/ 111 public synchronized void paint(Graphics g) { 112 try { 113 while ( ! initialized ) 114 Thread.currentThread().sleep(5); 115 } catch (InterruptedException e) {} 116 if (g instanceof PrintGraphics ) 117 System.out.println( "printing GraphApplet ..."); 118 } 119 120 public synchronized void print(Graphics g) { 121 try { 122 while ( ! initialized ) 123 Thread.currentThread().sleep(5); 124 } catch (InterruptedException e) {} 125 System.out.println( "Print Applet " + g); 126 panel.print(g); 127 } 128 129 public void print() { 130 // System.out.println( "Print Applet"); 131 Toolkit kit = getToolkit(); 132 try { 133 134 PrintJob job = kit.getPrintJob( new Frame("x"), "PrintableFrame print job", 135 null); 136 // do the printing if the user didn't cancel the print job 137 if (job != null) { 138 Graphics g = job.getGraphics(); 139 printAll(g); // not paint(g) 140 g.dispose(); // finish with this page 141 job.end(); // finish with the PrintJob 142 } 143 } catch (Exception ex) { 144 System.out.println( "print exception " + ex); 145 } 146 } 147 148 /** 149 ** 150 ** @param panel the container for nodes 151 ** 152 **/ 153 private void 154 fill( GraphPanel panel ) { 155 panel.addNodes("Node1", "Node2", "Node3" ); 156 } 157 }