Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/awt/Component/F10TopToplevel/F10TopToplevel.java
48795 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23test24@bug 653317525@summary Block F10 if closest toplevel to keystroke target is not a Frame.26@author yuri nesterenko : area=awt.toplevel27@run applet F10TopToplevel.html28*/29303132/**33* F10TopToplevel.java34*35* summary: tests if F10 has no effect if focused toplevel if not Frame36*/3738import java.applet.Applet;39import java.awt.*;40import java.awt.event.*;414243public class F10TopToplevel extends Applet44{45//Declare things used in the test, like buttons and labels here46Frame frame;47Dialog dialog;48volatile boolean menuToggled = false;4950public void init()51{52setLayout (new BorderLayout ());5354}//End init()5556public void start ()57{58//Get things going. Request focus, set size, et cetera59setSize (200,200);60setVisible(true);61validate();626364//What would normally go into main() will probably go here.65//Use System.out.println for diagnostic messages that you want66//to read after the test is done.67MenuBar mb;68Menu menu;69MenuItem item;70frame = new Frame("am below");71frame.setMenuBar( (mb=new MenuBar()) );72menu = new Menu("nu");73menu.add((item = new MenuItem("item")));74item.addActionListener( new ActionListener() {75public void actionPerformed( ActionEvent ae ) {76menuToggled = true;77}78});79mb.add(menu);8081frame.setSize(200,200);82frame.setLocation( 400,100 );83frame.setVisible( true );8485dialog = new Dialog(frame);86dialog.setSize( 100,100 );87dialog.setVisible(true);8889Robot robot;90try {91robot = new Robot();92robot.setAutoDelay(5);93} catch(AWTException e){94throw new RuntimeException("cannot create robot.", e);95}96robot.waitForIdle();97robot.mouseMove(dialog.getLocationOnScreen().x + dialog.getWidth()/2,98dialog.getLocationOnScreen().y + dialog.getHeight()/2 );99robot.waitForIdle();100robot.mousePress(InputEvent.BUTTON1_MASK);101robot.mouseRelease(InputEvent.BUTTON1_MASK);102robot.waitForIdle();103robot.keyPress(KeyEvent.VK_F10);104robot.keyRelease(KeyEvent.VK_F10);105106robot.delay(10);107robot.keyPress(KeyEvent.VK_ENTER);108robot.waitForIdle();109robot.keyRelease(KeyEvent.VK_ENTER);110111robot.waitForIdle();112113if(menuToggled) {114throw new RuntimeException("Oops! Menu should not open.");115}116117}// start()118119}// class F10TopToplevel120121122