1 /* 2 * Copyright (c) 2005, 2018, 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 /* 27 @test 28 @key headful 29 @bug 6260648 30 @summary Tests that WINDOW_DESTROY event can be handled by overriding handleEvent(). Also, 31 tests that handleEvent() is not called by AWT if any listener is added to the component 32 (i. e. when post-1.1 events schema is used) 33 @run main HandleWindowDestroyTest 34 */ 35 36 import java.awt.*; 37 import java.awt.event.*; 38 39 public class HandleWindowDestroyTest { 40 41 private static volatile boolean handleEventCalled; 42 43 public static void main(final String[] args) { 44 Robot robot; 45 try { 46 robot = new Robot(); 47 }catch(Exception ex) { 48 ex.printStackTrace(); 49 throw new RuntimeException("Unexpected failure"); 50 } 51 52 Frame f = new Frame("Frame") 53 { 54 public boolean handleEvent(Event e) 55 { 56 if (e.id == Event.WINDOW_DESTROY) 57 { 58 handleEventCalled = true; 59 } 60 return super.handleEvent(e); 61 } 62 }; 63 f.setBounds(100, 100, 100, 100); 64 f.setVisible(true); 65 robot.waitForIdle(); 66 67 handleEventCalled = false; 68 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(f, Event.WINDOW_DESTROY)); 69 robot.waitForIdle(); 70 71 if (!handleEventCalled) 72 { 73 throw new RuntimeException("Test FAILED: handleEvent() is not called"); 74 } 75 76 f.addWindowListener(new WindowAdapter() 77 { 78 }); 79 80 handleEventCalled = false; 81 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(f, Event.WINDOW_DESTROY)); 82 robot.waitForIdle(); 83 84 if (handleEventCalled) 85 { 86 throw new RuntimeException("Test FAILED: handleEvent() is called event with a listener added"); 87 } 88 } 89 }