|
1 | 1 | /* |
2 | | - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2003, 2008, 2024 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
21 | 21 | * questions. |
22 | 22 | */ |
23 | 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 | | - |
32 | 24 | import java.awt.Color; |
33 | 25 | import java.awt.Component; |
34 | 26 | import java.awt.Window; |
35 | 27 | import java.awt.event.ActionEvent; |
36 | 28 | import java.awt.event.ActionListener; |
37 | | -import javax.swing.JApplet; |
38 | 29 | import javax.swing.JButton; |
39 | 30 | import javax.swing.JColorChooser; |
40 | 31 | import javax.swing.JDialog; |
41 | 32 | import javax.swing.JFrame; |
42 | 33 |
|
43 | | -public class Test4759934 extends JApplet implements ActionListener { |
| 34 | +/* |
| 35 | + * @test |
| 36 | + * @bug 4759934 |
| 37 | + * @library /java/awt/regtesthelpers |
| 38 | + * @build PassFailJFrame |
| 39 | + * @summary Tests windows activation problem |
| 40 | + * @run main/manual Test4759934 |
| 41 | + */ |
| 42 | +public class Test4759934 { |
44 | 43 | private static final String CMD_DIALOG = "Show Dialog"; // NON-NLS: first button |
45 | 44 | private static final String CMD_CHOOSER = "Show ColorChooser"; // NON-NLS: second button |
46 | 45 |
|
47 | | - private final JFrame frame = new JFrame("Test"); // NON-NLS: frame title |
| 46 | + private static JFrame frame; |
48 | 47 |
|
49 | | - public void init() { |
50 | | - show(this.frame, CMD_DIALOG); |
51 | | - } |
| 48 | + private static ActionListener al = new ActionListener() { |
| 49 | + @Override |
| 50 | + public void actionPerformed(ActionEvent event) { |
| 51 | + String command = event.getActionCommand(); |
| 52 | + if (CMD_DIALOG.equals(command)) { |
| 53 | + JDialog dialog = new JDialog(frame, "Dialog"); // NON-NLS: dialog title |
| 54 | + dialog.setLocation(200, 0); |
| 55 | + show(dialog, CMD_CHOOSER, true); |
| 56 | + } |
| 57 | + else if (CMD_CHOOSER.equals(command)) { |
| 58 | + Object source = event.getSource(); |
| 59 | + Component component = (source instanceof Component) |
| 60 | + ? (Component) source |
| 61 | + : null; |
52 | 62 |
|
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); |
| 63 | + JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title |
| 64 | + } |
59 | 65 | } |
60 | | - else if (CMD_CHOOSER.equals(command)) { |
61 | | - Object source = event.getSource(); |
62 | | - Component component = (source instanceof Component) |
63 | | - ? (Component) source |
64 | | - : null; |
| 66 | + }; |
65 | 67 |
|
66 | | - JColorChooser.showDialog(component, "ColorChooser", Color.BLUE); // NON-NLS: title |
67 | | - } |
| 68 | + public static void main(String[] args) throws Exception { |
| 69 | + String instructions = "1. Press button \"Show Dialog\" at the frame \"Test\" and\n" + |
| 70 | + " the dialog with button \"Show ColorChooser\" should appears.\n" + |
| 71 | + "2. Press button \"Show ColorChooser\" at the dialog \"Dialog\" and\n" + |
| 72 | + " the colorchooser should appears.\n" + |
| 73 | + "3. Press the button \"Cancel\" of colorchooser.\n" + |
| 74 | + " If the focus will come to the frame \"Test\" then test fails.\n" + |
| 75 | + " If the focus will come to the dialog \"Dialog\" then test passes."; |
| 76 | + |
| 77 | + PassFailJFrame.builder() |
| 78 | + .title("Test4759934") |
| 79 | + .instructions(instructions) |
| 80 | + .rows(5) |
| 81 | + .columns(40) |
| 82 | + .testTimeOut(10) |
| 83 | + .testUI(Test4759934::test) |
| 84 | + .build() |
| 85 | + .awaitAndCheck(); |
68 | 86 | } |
69 | 87 |
|
70 | | - private void show(Window window, String command) { |
| 88 | + public static JFrame test() { |
| 89 | + frame = new JFrame("ColorChooser dialog on button press test"); |
| 90 | + show(frame, CMD_DIALOG, false); |
| 91 | + return frame; |
| 92 | + } |
| 93 | + |
| 94 | + private static void show(Window window, String command, boolean setVisible) { |
71 | 95 | JButton button = new JButton(command); |
72 | 96 | button.setActionCommand(command); |
73 | | - button.addActionListener(this); |
| 97 | + button.addActionListener(al); |
| 98 | + |
74 | 99 | button.setFont(button.getFont().deriveFont(64.0f)); |
75 | 100 |
|
76 | 101 | window.add(button); |
77 | 102 | window.pack(); |
78 | | - window.setVisible(true); |
| 103 | + if (setVisible) { |
| 104 | + window.setVisible(true); |
| 105 | + } |
79 | 106 | } |
80 | 107 | } |
0 commit comments