1 /** 2 * Copyright (c) 2012, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 import java.awt.*; 27 import java.awt.event.*; 28 29 public class MyCanvas extends Canvas { 30 31 static { 32 try { 33 System.loadLibrary("mylib"); 34 } catch (Throwable t) { 35 System.out.println("Test failed!!"); 36 t.printStackTrace(); 37 System.exit(1); 38 } 39 } 40 41 public native void paint(Graphics g); 42 43 public static void main(String[] args) { 44 try { 45 Robot robot = new Robot(); 46 Frame f = new Frame(); 47 f.setBounds(0, 0, 100, 100); 48 f.add(new MyCanvas()); 49 f.addWindowListener(new WindowAdapter() { 50 public void windowClosing(WindowEvent ev) { 51 System.exit(0); 52 } 53 }); 54 f.setVisible(true); 55 robot.delay(5000); 56 Color col1 = new Color(0, 0, 0); 57 Color col2 = robot.getPixelColor(f.getX()+50, f.getY()+50); 58 if (col1.equals(col2)) { 59 System.out.println("Test passed!"); 60 } else { 61 throw new RuntimeException("Color of JAWT canvas is wrong or " + 62 "it was not rendered. " + "Check that other windows " + 63 "do not block the test frame."); 64 } 65 System.exit(0); 66 } catch (Throwable t) { 67 System.out.println("Test failed!"); 68 t.printStackTrace(); 69 System.exit(1); 70 } 71 } 72 }