Path: blob/master/test/jdk/java/awt/Frame/GetBoundsResizeTest/GetBoundsResizeTest.java
41153 views
/*1* Copyright (c) 1998, 2014, 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*/2223/* @test24@bug 410309525@summary Test for getBounds() after a Frame resize.26@author andrei.dmitriev : area=awt.toplevel27@run main/manual GetBoundsResizeTest28*/2930import java.applet.Applet;31import java.lang.*;32import java.awt.*;33import java.awt.event.*;3435class Globals {36static boolean testPassed=false;37static Thread mainThread=null;38}3940public class GetBoundsResizeTest extends Applet {4142public static void main(String args[]) throws Exception {43GetBoundsResizeTest app = new GetBoundsResizeTest();44app.start();45Globals.mainThread = Thread.currentThread();46try {47Thread.sleep(300000);48} catch (InterruptedException e) {49if (!Globals.testPassed)50throw new Exception("GetBoundsResizeTest failed.");51}52}5354public void start()55{56String[] message = {57"Resize the window using the upper left corner.",58"Press the button to print the result of getBounds() to the terminal.",59"If getBounds() prints the correct values for the window",60"then click Pass, else click Fail."61};62new TestDialog(new Frame(), "GetBoundsResizeTest", message).start();63new GetBoundsResizeTester("GetBoundsResizeTester").start();64}65}6667////////////////////////////////////////////////////////////////////////68// Test Dialog69////////////////////////////////////////////////////////////////////////7071class TestDialog extends Dialog72implements ActionListener {7374static TextArea output;75Button passButton;76Button failButton;77String name;7879public TestDialog(Frame frame, String name, String[] message)80{81super(frame, name + " Pass/Fail Dialog");82this.name = name;83int maxStringLength = 0;84for (int i=0; i<message.length; i++) {85maxStringLength = Math.max(maxStringLength, message[i].length());86}87output = new TextArea(10, maxStringLength);88add("North", output);89for (int i=0; i<message.length; i++){90output.append(message[i] + "\n");91}92Panel buttonPanel = new Panel();93passButton = new Button("Pass");94failButton = new Button("Fail");95passButton.addActionListener(this);96failButton.addActionListener(this);97buttonPanel.add(passButton);98buttonPanel.add(failButton);99add("South", buttonPanel);100pack();101}102103public void start()104{105show();106}107108public void actionPerformed(ActionEvent event)109{110if ( event.getSource() == passButton ) {111Globals.testPassed = true;112System.err.println(name + " Passed.");113}114else if ( event.getSource() == failButton ) {115Globals.testPassed = false;116System.err.println(name + " Failed.");117}118this.dispose();119if (Globals.mainThread != null)120Globals.mainThread.interrupt();121}122}123124125////////////////////////////////////////////////////////////////////////126// Test Class127////////////////////////////////////////////////////////////////////////128129class GetBoundsResizeTester extends Frame {130Button b = new Button("Press");131132GetBoundsResizeTester(String name)133{134super(name);135final Frame f = this;136Panel p = new Panel();137f.add(p);138p.setLayout(new BorderLayout());139b.addActionListener(new ActionListener() {140public void actionPerformed(ActionEvent be){141Point cp = b.getLocationOnScreen();142TestDialog.output.append("Current Frame.getBounds() = " + f.getBounds()+"\n");143}144});145p.add("Center", b);146f.pack();147}148149public void start ()150{151setVisible(true);152Robot robot;153try {154robot = new Robot();155robot.waitForIdle();156}catch(Exception ignorex) {157}158Point cp = b.getLocationOnScreen();159TestDialog.output.append("Original Frame.getBounds() = " + this.getBounds()+"\n");160}161162public static void main(String[] args)163{164new GetBoundsResizeTester("GetBoundsResizeTester").start();165}166167}168169170