1 /**
   2  * Copyright (c) 2007, 2012 Oracle and/or its affiliates. All rights reserved.
   3  * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
   4  *
   5  *
   6  *
   7  *
   8  *
   9  *
  10  *
  11  *
  12  *
  13  *
  14  *
  15  *
  16  *
  17  *
  18  *
  19  *
  20  *
  21  *
  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 
  39     public native void paint(Graphics g);
  40 
  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.show();
  53             robot.delay(10000);
  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 }