1/*
2 * Copyright (c) 2003, 2008, 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/*
25 * @test
26 * @bug 4759934
27 * @summary Tests windows activation problem
28 * @author Andrey Pikalev
29 * @run applet/manual=yesno Test4759934.html
30 */
31
32import java.awt.Color;
33import java.awt.Component;
34import java.awt.Window;
35import java.awt.event.ActionEvent;
36import java.awt.event.ActionListener;
37import javax.swing.JApplet;
38import javax.swing.JButton;
39import javax.swing.JColorChooser;
40import javax.swing.JDialog;
41import javax.swing.JFrame;
42
43public class Test4759934 extends JApplet implements ActionListener {
44    private static final String CMD_DIALOG = "Show Dialog"; // NON-NLS: first button
45    private static final String CMD_CHOOSER = "Show ColorChooser"; // NON-NLS: second button
46
47    private final JFrame frame = new JFrame("Test"); // NON-NLS: frame title
48
49    public void init() {
50        show(this.frame, CMD_DIALOG);
51    }
52
53    public void actionPerformed(ActionEvent event) {
54        String command = event.getActionCommand();
55        if (CMD_DIALOG.equals(command)) {
56            JDialog dialog = new JDialog(this.frame, "Dialog"); // NON-NLS: dialog title
57            dialog.setLocation(200, 0);
58            show(dialog, CMD_CHOOSER);
59        }
60        else if (CMD_CHOOSER.equals(command)) {
61            Object source = event.getSource();
62            Component component = (source instanceof Component)
63                    ? (Component) source
64                    : null;
65
66            JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title
67        }
68    }
69
70    private void show(Window window, String command) {
71        JButton button = new JButton(command);
72        button.setActionCommand(command);
73        button.addActionListener(this);
74        button.setFont(button.getFont().deriveFont(64.0f));
75
76        window.add(button);
77        window.pack();
78        window.setVisible(true);
79    }
80}
81