Path: blob/master/test/jdk/java/awt/JAWT/MyCanvas.java
41149 views
/*1* Copyright (c) 2012, 2013, 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*/2223import java.awt.*;24import java.awt.event.*;2526public class MyCanvas extends Canvas {2728static {29try {30System.loadLibrary("mylib");31} catch (Throwable t) {32System.out.println("Test failed!!");33t.printStackTrace();34System.exit(1);35}36}3738public native void paint(Graphics g);3940public static void main(String[] args) {41try {42Robot robot = new Robot();43Frame f = new Frame();44f.setBounds(0, 0, 100, 100);45f.add(new MyCanvas());46f.addWindowListener(new WindowAdapter() {47public void windowClosing(WindowEvent ev) {48System.exit(0);49}50});51f.setVisible(true);52robot.delay(5000);53Color col1 = new Color(0, 0, 0);54Color col2 = robot.getPixelColor(f.getX()+50, f.getY()+50);55if (col1.equals(col2)) {56System.out.println("Test passed!");57} else {58throw new RuntimeException("Color of JAWT canvas is wrong or " +59"it was not rendered. " + "Check that other windows " +60"do not block the test frame.");61}62System.exit(0);63} catch (Throwable t) {64System.out.println("Test failed!");65t.printStackTrace();66System.exit(1);67}68}69}707172