Path: blob/master/test/jdk/java/awt/Frame/InitialMaximizedTest/InitialMaximizedTest.java
41153 views
/*1* Copyright (c) 2003, 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 4464714 636589826@summary Frames cannot be shown initially maximized27@author Valeriy Ushakov: area=toplevel28@run applet/manual=yesno InitialMaximizedTest.html29*/303132/**33* InitialMaximizedTest.java34*35* summary:36*/3738import java.applet.Applet;39import java.awt.*;404142public class InitialMaximizedTest extends Applet43{44Frame f;4546public void init()47{48this.setLayout (new BorderLayout ());4950String[] instructions =51{52"This test creates a frame that is initially maximized.",53"Press PASS if frame is shown initially maximized, else press FAIL"54};55Sysout.createDialogWithInstructions( instructions );5657}//End init()5859public void start ()60{61//Get things going. Request focus, set size, et cetera62setSize (200,200);63setVisible(true);64validate();6566f = new Frame("The frame SHOULD be shown MAXIMIZED");67f.setSize(300, 300);68f.setLocation(50, 50);69f.setExtendedState(Frame.MAXIMIZED_BOTH);70f.setVisible(true);71}// start()7273}// class InitialMaximizedTest7475/* Place other classes related to the test after this line */767778798081/****************************************************82Standard Test Machinery83DO NOT modify anything below -- it's a standard84chunk of code whose purpose is to make user85interaction uniform, and thereby make it simpler86to read and understand someone else's test.87****************************************************/8889/**90This is part of the standard test machinery.91It creates a dialog (with the instructions), and is the interface92for sending text messages to the user.93To print the instructions, send an array of strings to Sysout.createDialog94WithInstructions method. Put one line of instructions per array entry.95To display a message for the tester to see, simply call Sysout.println96with the string to be displayed.97This mimics System.out.println but works within the test harness as well98as standalone.99*/100101class Sysout102{103private static TestDialog dialog;104105public static void createDialogWithInstructions( String[] instructions )106{107dialog = new TestDialog( new Frame(), "Instructions" );108dialog.printInstructions( instructions );109dialog.setVisible(true);110println( "Any messages for the tester will display here." );111}112113public static void createDialog( )114{115dialog = new TestDialog( new Frame(), "Instructions" );116String[] defInstr = { "Instructions will appear here. ", "" } ;117dialog.printInstructions( defInstr );118dialog.setVisible(true);119println( "Any messages for the tester will display here." );120}121122123public static void printInstructions( String[] instructions )124{125dialog.printInstructions( instructions );126}127128129public static void println( String messageIn )130{131dialog.displayMessage( messageIn );132}133134}// Sysout class135136/**137This is part of the standard test machinery. It provides a place for the138test instructions to be displayed, and a place for interactive messages139to the user to be displayed.140To have the test instructions displayed, see Sysout.141To have a message to the user be displayed, see Sysout.142Do not call anything in this dialog directly.143*/144class TestDialog extends Dialog145{146147TextArea instructionsText;148TextArea messageText;149int maxStringLength = 80;150151//DO NOT call this directly, go through Sysout152public TestDialog( Frame frame, String name )153{154super( frame, name );155int scrollBoth = TextArea.SCROLLBARS_BOTH;156instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );157add( "North", instructionsText );158159messageText = new TextArea( "", 5, maxStringLength, scrollBoth );160add("Center", messageText);161162pack();163164setVisible(true);165}// TestDialog()166167//DO NOT call this directly, go through Sysout168public void printInstructions( String[] instructions )169{170//Clear out any current instructions171instructionsText.setText( "" );172173//Go down array of instruction strings174175String printStr, remainingStr;176for( int i=0; i < instructions.length; i++ )177{178//chop up each into pieces maxSringLength long179remainingStr = instructions[ i ];180while( remainingStr.length() > 0 )181{182//if longer than max then chop off first max chars to print183if( remainingStr.length() >= maxStringLength )184{185//Try to chop on a word boundary186int posOfSpace = remainingStr.187lastIndexOf( ' ', maxStringLength - 1 );188189if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;190191printStr = remainingStr.substring( 0, posOfSpace + 1 );192remainingStr = remainingStr.substring( posOfSpace + 1 );193}194//else just print195else196{197printStr = remainingStr;198remainingStr = "";199}200201instructionsText.append( printStr + "\n" );202203}// while204205}// for206207}//printInstructions()208209//DO NOT call this directly, go through Sysout210public void displayMessage( String messageIn )211{212messageText.append( messageIn + "\n" );213System.out.println(messageIn);214}215216}// TestDialog class217218219