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 Window
  30  * @author Aruna Samji
  31  * @library ../../../lib/testlibrary
  32  * @build ExtendedRobot
  33  * @run main TaskWindow
  34  */
  35 
  36 public class TaskWindow extends Task<GUIComponent> {
  37 
  38     Frame frame;
  39     Window window;
  40     Panel panel;
  41     Button button;
  42     Canvas canvas;
  43     Checkbox checkbox;
  44     Choice choice;
  45     Container container;
  46     Label label;
  47     List list;
  48     Scrollbar scrollbar;
  49     TextArea textarea;
  50     TextField textfield;
  51 
  52     public static void main (String[] args) throws Exception {
  53         new TaskWindow(GUIComponent.class, new ExtendedRobot()).runTask();
  54     }
  55 
  56     TaskWindow(Class guiClass, ExtendedRobot robot) throws Exception {
  57         super(guiClass, robot);
  58     }
  59 
  60     public void task() throws Exception {
  61 
  62         for (int i = 0; i < 10; i++) {
  63             EventQueue.invokeAndWait(() -> {
  64                 frame = new Frame("WindowTest");
  65                 window = new Window(frame);
  66                 window.setBackground(Color.red);
  67                 window.setSize(600, 270);
  68 
  69                 panel = new Panel();
  70 
  71                 container = new Container();
  72                 container.setLayout(new FlowLayout());
  73 
  74                 button = new Button("Button");
  75                 canvas = new Canvas();
  76 
  77                 checkbox = new Checkbox("CheckBox");
  78                 choice = new Choice();
  79                 choice.add("Choice 1");
  80                 choice.add("Choice 2");
  81                 choice.add("Choice 3");
  82                 choice.add("Choice 4");
  83 
  84                 label = new Label("Label");
  85                 list = new List(2);
  86                 list.add("list 1");
  87                 list.add("list 2");
  88                 list.add("list 3");
  89                 scrollbar = new Scrollbar();
  90 
  91                 textarea = new TextArea("TextArea", 3, 10);
  92                 textfield = new TextField("TextField");
  93 
  94                 container.add(button);
  95                 container.add(canvas);
  96                 container.add(checkbox);
  97                 container.add(choice);
  98                 container.add(label);
  99                 container.add(list);
 100                 container.add(scrollbar);
 101                 container.add(textarea);
 102                 container.add(textfield);
 103 
 104                 panel.add(container);
 105                 window.add(panel);
 106 
 107                 window.setVisible(true);
 108             });
 109             robot.waitForIdle(1000);
 110 
 111             EventQueue.invokeAndWait(() -> {
 112                 container.remove(button);
 113                 container.remove(canvas);
 114                 container.remove(checkbox);
 115                 container.remove(choice);
 116                 container.remove(label);
 117                 container.remove(list);
 118                 container.remove(scrollbar);
 119                 container.remove(textarea);
 120                 container.remove(textfield);
 121 
 122                 panel.remove(container);
 123                 window.remove(panel);
 124                 window.dispose();
 125                 frame.dispose();
 126             });
 127             robot.waitForIdle(1000);
 128             robot.waitForIdle(1000);
 129         }
 130     }
 131 }