1 /*
   2  * Copyright (c) 2004, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.*;
  25 import java.awt.Label;
  26 
  27 /*
  28  * @test
  29  * @summary Create and dispose the Frame
  30  * @author Aruna Samji
  31  * @library ../../../lib/testlibrary
  32  * @build ExtendedRobot
  33  * @run main TaskFrame
  34  */
  35 
  36 public class TaskFrame extends Task<GUIComponent> {
  37 
  38     public static void main (String[] args) throws Exception {
  39         new TaskFrame(GUIComponent.class, new ExtendedRobot()).runTask();
  40     }
  41 
  42     public TaskFrame(Class guiClass, ExtendedRobot robot) throws Exception {
  43         super(guiClass, robot);
  44     }
  45 
  46     public void task() throws Exception {
  47         Frame[] frame = new Frame[1];
  48 
  49         for (int i = 0; i < 10; i++) {
  50             EventQueue.invokeAndWait(() -> {
  51                 frame[0] = new Frame("FrameTest");
  52                 frame[0].setBackground(Color.blue);
  53                 frame[0].setSize(600, 270);
  54 
  55                 Panel panel = new Panel();
  56 
  57                 Container container = new Container();
  58                 container.setLayout(new FlowLayout());
  59 
  60                 Button button = new Button("Button");
  61                 Canvas canvas = new Canvas();
  62                 Checkbox checkbox = new Checkbox("CheckBox");
  63                 Choice choice = new Choice();
  64                 choice.add("Choice 1");
  65                 choice.add("Choice 2");
  66                 choice.add("Choice 3");
  67                 choice.add("Choice 4");
  68 
  69                 Label label = new Label("Label");
  70                 List list = new List(2);
  71                 list.add("list 1");
  72                 list.add("list 2");
  73                 list.add("list 3");
  74                 Scrollbar scrollbar = new Scrollbar();
  75 
  76                 TextArea textarea = new TextArea("TextArea", 3, 10);
  77                 TextField textfield = new TextField("TextField");
  78 
  79                 container.add(button);
  80                 container.add(canvas);
  81                 container.add(checkbox);
  82                 container.add(choice);
  83                 container.add(label);
  84                 container.add(list);
  85                 container.add(scrollbar);
  86                 container.add(textarea);
  87                 container.add(textfield);
  88 
  89                 panel.add(container);
  90                 frame[0].add(panel);
  91 
  92                 frame[0].setVisible(true);
  93             });
  94             robot.waitForIdle(1000);
  95 
  96             EventQueue.invokeAndWait(frame[0]::dispose);
  97             robot.waitForIdle(1000);
  98         }
  99     }
 100 }