< prev index next >

test/jdk/java/awt/Window/HandleWindowDestroyTest/HandleWindowDestroyTest.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2014, 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   @bug 6260648
  29   @summary Tests that WINDOW_DESTROY event can be handled by overriding handleEvent(). Also,
  30 tests that handleEvent() is not called by AWT if any listener is added to the component
  31 (i. e. when post-1.1 events schema is used)
  32   @author artem.ananiev: area=awt.event
  33   @run applet HandleWindowDestroyTest.html
  34 */
  35 
  36 import java.applet.*;
  37 
  38 import java.awt.*;
  39 import java.awt.event.*;
  40 
  41 public class HandleWindowDestroyTest extends Applet
  42 {
  43     private volatile boolean handleEventCalled;
  44 
  45     public void start ()
  46     {
  47         setSize (200,200);
  48         setVisible(true);
  49         validate();
  50 

  51         Robot robot;
  52         try {
  53             robot = new Robot();
  54         }catch(Exception ex) {
  55             ex.printStackTrace();
  56             throw new RuntimeException("Unexpected failure");
  57         }
  58 
  59         Frame f = new Frame("Frame")
  60         {
  61             public boolean handleEvent(Event e)
  62             {
  63                 if (e.id == Event.WINDOW_DESTROY)
  64                 {
  65                     handleEventCalled = true;
  66                 }
  67                 return super.handleEvent(e);
  68             }
  69         };
  70         f.setBounds(100, 100, 100, 100);


   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);


< prev index next >