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