Path: blob/master/test/jdk/java/awt/Frame/ShownOnPack/ShownOnPack.java
41153 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*/2223/*24test25@bug 652585026@summary Iconified frame gets shown after pack()27@author anthony.petrov@...: area=awt.toplevel28@run applet/manual=yesno ShownOnPack.html29*/303132/**33* ShownOnPack.java34*35* summary:36*/3738import java.applet.Applet;39import java.awt.*;4041public class ShownOnPack extends Applet42{43//Declare things used in the test, like buttons and labels here44Frame f;4546public void init()47{48//Create instructions for the user here, as well as set up49// the environment -- set the layout manager, add buttons,50// etc.51this.setLayout (new BorderLayout ());5253String[] instructions =54{55"This test creates an invisible and iconified frame that should not become visible.",56"If you observe the window titled 'Should NOT BE SHOWN' in the taskbar, press FAIL,",57"else press PASS"58};59Sysout.createDialogWithInstructions( instructions );6061}//End init()6263public void start ()64{65//Get things going. Request focus, set size, et cetera66setSize (200,200);67setVisible(true);68validate();6970//What would normally go into main() will probably go here.71//Use System.out.println for diagnostic messages that you want72// to read after the test is done.73//Use Sysout.println for messages you want the tester to read.74f = new Frame("Should NOT BE SHOWN");75f.setExtendedState(Frame.ICONIFIED);76f.pack();77}// start()7879//The rest of this class is the actions which perform the test...8081//Use Sysout.println to communicate with the user NOT System.out!!82//Sysout.println ("Something Happened!");8384}// class ShownOnPack8586/* Place other classes related to the test after this line */878889909192/****************************************************93Standard Test Machinery94DO NOT modify anything below -- it's a standard95chunk of code whose purpose is to make user96interaction uniform, and thereby make it simpler97to read and understand someone else's test.98****************************************************/99100/**101This is part of the standard test machinery.102It creates a dialog (with the instructions), and is the interface103for sending text messages to the user.104To print the instructions, send an array of strings to Sysout.createDialog105WithInstructions method. Put one line of instructions per array entry.106To display a message for the tester to see, simply call Sysout.println107with the string to be displayed.108This mimics System.out.println but works within the test harness as well109as standalone.110*/111112class Sysout113{114private static TestDialog dialog;115116public static void createDialogWithInstructions( String[] instructions )117{118dialog = new TestDialog( new Frame(), "Instructions" );119dialog.printInstructions( instructions );120dialog.setVisible(true);121println( "Any messages for the tester will display here." );122}123124public static void createDialog( )125{126dialog = new TestDialog( new Frame(), "Instructions" );127String[] defInstr = { "Instructions will appear here. ", "" } ;128dialog.printInstructions( defInstr );129dialog.setVisible(true);130println( "Any messages for the tester will display here." );131}132133134public static void printInstructions( String[] instructions )135{136dialog.printInstructions( instructions );137}138139140public static void println( String messageIn )141{142dialog.displayMessage( messageIn );143}144145}// Sysout class146147/**148This is part of the standard test machinery. It provides a place for the149test instructions to be displayed, and a place for interactive messages150to the user to be displayed.151To have the test instructions displayed, see Sysout.152To have a message to the user be displayed, see Sysout.153Do not call anything in this dialog directly.154*/155class TestDialog extends Dialog156{157158TextArea instructionsText;159TextArea messageText;160int maxStringLength = 80;161162//DO NOT call this directly, go through Sysout163public TestDialog( Frame frame, String name )164{165super( frame, name );166int scrollBoth = TextArea.SCROLLBARS_BOTH;167instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );168add( "North", instructionsText );169170messageText = new TextArea( "", 5, maxStringLength, scrollBoth );171add("Center", messageText);172173pack();174175setVisible(true);176}// TestDialog()177178//DO NOT call this directly, go through Sysout179public void printInstructions( String[] instructions )180{181//Clear out any current instructions182instructionsText.setText( "" );183184//Go down array of instruction strings185186String printStr, remainingStr;187for( int i=0; i < instructions.length; i++ )188{189//chop up each into pieces maxSringLength long190remainingStr = instructions[ i ];191while( remainingStr.length() > 0 )192{193//if longer than max then chop off first max chars to print194if( remainingStr.length() >= maxStringLength )195{196//Try to chop on a word boundary197int posOfSpace = remainingStr.198lastIndexOf( ' ', maxStringLength - 1 );199200if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;201202printStr = remainingStr.substring( 0, posOfSpace + 1 );203remainingStr = remainingStr.substring( posOfSpace + 1 );204}205//else just print206else207{208printStr = remainingStr;209remainingStr = "";210}211212instructionsText.append( printStr + "\n" );213214}// while215216}// for217218}//printInstructions()219220//DO NOT call this directly, go through Sysout221public void displayMessage( String messageIn )222{223messageText.append( messageIn + "\n" );224System.out.println(messageIn);225}226227}// TestDialog class228229230