1163N/A/*
2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
1163N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1163N/A *
1163N/A * This code is free software; you can redistribute it and/or modify it
1163N/A * under the terms of the GNU General Public License version 2 only, as
1163N/A * published by the Free Software Foundation.
1163N/A *
1163N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1163N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1163N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1163N/A * version 2 for more details (a copy is included in the LICENSE file that
1163N/A * accompanied this code).
1163N/A *
1163N/A * You should have received a copy of the GNU General Public License version
1163N/A * 2 along with this work; if not, write to the Free Software Foundation,
1163N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1163N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1163N/A */
1163N/A
1163N/A/*
1163N/A * @test %I% %E%
1163N/A * @bug 6683728
1163N/A * @summary Tests that a JApplet in a translucent JFrame works properly
1163N/A * @author Kenneth.Russell@sun.com: area=Graphics
1163N/A * @compile -XDignore.symbol.file=true TranslucentJAppletTest.java
1163N/A * @run main/manual/othervm TranslucentJAppletTest
1163N/A */
1163N/A
1163N/Aimport java.awt.*;
1163N/Aimport java.awt.image.*;
1163N/A
1163N/Aimport javax.swing.*;
1163N/A
1163N/Apublic class TranslucentJAppletTest {
1163N/A
1163N/A private static JFrame frame;
1163N/A private static volatile boolean paintComponentCalled = false;
1163N/A
1163N/A private static void initAndShowGUI() {
1163N/A frame = new JFrame();
1163N/A JApplet applet = new JApplet();
3946N/A applet.setBackground(new Color(0, 0, 0, 0));
1163N/A JPanel panel = new JPanel() {
1163N/A protected void paintComponent(Graphics g) {
1163N/A paintComponentCalled = true;
1163N/A g.setColor(Color.RED);
1163N/A g.fillOval(0, 0, getWidth(), getHeight());
1163N/A }
1163N/A };
1163N/A panel.setDoubleBuffered(false);
1163N/A panel.setOpaque(false);
1163N/A applet.add(panel);
1163N/A frame.add(applet);
1163N/A frame.setBounds(100, 100, 200, 200);
1163N/A frame.setUndecorated(true);
1163N/A frame.setBackground(new Color(0, 0, 0, 0));
1163N/A frame.setVisible(true);
1163N/A }
1163N/A
1163N/A public static void main(String[] args)
1163N/A throws Exception
1163N/A {
1163N/A sun.awt.SunToolkit tk = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
1163N/A
1163N/A Robot r = new Robot();
1163N/A Color color1 = r.getPixelColor(100, 100); // (0, 0) in frame coordinates
1163N/A
1163N/A SwingUtilities.invokeAndWait(new Runnable() {
1163N/A public void run() {
1163N/A initAndShowGUI();
1163N/A }
1163N/A });
1163N/A tk.realSync();
1163N/A
1163N/A if (!paintComponentCalled) {
1163N/A throw new RuntimeException("Test FAILED: panel's paintComponent() method is not called");
1163N/A }
1163N/A
1163N/A Color newColor1 = r.getPixelColor(100, 100);
1163N/A // unfortunately, robot.getPixelColor() doesn't work for some unknown reason
1163N/A // Color newColor2 = r.getPixelColor(200, 200);
1163N/A BufferedImage bim = r.createScreenCapture(new Rectangle(200, 200, 1, 1));
1163N/A Color newColor2 = new Color(bim.getRGB(0, 0));
1163N/A
1163N/A // Frame must be transparent at (100, 100) in screen coords
1163N/A if (!color1.equals(newColor1)) {
1163N/A System.err.println("color1 = " + color1);
1163N/A System.err.println("newColor1 = " + newColor1);
1163N/A throw new RuntimeException("Test FAILED: frame pixel at (0, 0) is not transparent");
1163N/A }
1163N/A
1163N/A // Frame must be RED at (200, 200) in screen coords
1163N/A if (!newColor2.equals(Color.RED)) {
1163N/A System.err.println("newColor2 = " + newColor2);
1163N/A throw new RuntimeException("Test FAILED: frame pixel at (100, 100) is not red (transparent?)");
1163N/A }
1163N/A
1163N/A System.out.println("Test PASSED");
1163N/A }
1163N/A}