Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JOptionPane/7042497/JOptionPaneConfirmDlgTest.java
41153 views
1
/*
2
* Copyright (c) 2017, 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
* @test
25
* @bug 7042497
26
* @summary Verifies if JOptionPane.showInternalConfirmDialog
27
throws RuntimeException if parentComponent argument is null
28
* @run main/manual JOptionPaneConfirmDlgTest
29
*/
30
31
import java.awt.Component;
32
import java.awt.Dimension;
33
import java.awt.FlowLayout;
34
import java.awt.Toolkit;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.ActionListener;
37
import javax.swing.JButton;
38
import javax.swing.JFrame;
39
import javax.swing.JInternalFrame;
40
import javax.swing.JOptionPane;
41
import javax.swing.SwingUtilities;
42
43
public class JOptionPaneConfirmDlgTest {
44
JInternalFrame textFrame;
45
JFrame f = null;
46
47
public static void main(String[] args) throws Exception{
48
new JOptionPaneConfirmDlgTest();
49
}
50
51
public JOptionPaneConfirmDlgTest() throws Exception {
52
53
try {
54
SwingUtilities.invokeAndWait(()->createGUI());
55
Thread.sleep(10000);
56
} finally {
57
SwingUtilities.invokeAndWait(()->f.dispose());
58
}
59
60
}
61
62
public void createGUI() {
63
JOptionPane.showMessageDialog(
64
(Component) null,
65
"An internalFrame with 2 buttons will be displayed. \n" +
66
" Press \"Hit me 1\" button. The bug causes a RuntimeException to be thrown here\n" +
67
" But If a confirmation dialog comes, test has passed\n" +
68
" Similarly, press \"Hit me 2\" button. The bug will cause a RuntimeException\n" +
69
" to be thrown here but if a confirmation dialog comes, test has passed.\n" +
70
" Close the dialog and frame.",
71
"information", JOptionPane.INFORMATION_MESSAGE);
72
f = new JFrame();
73
74
textFrame = new JInternalFrame("Main-Frame", true);
75
f.setContentPane(textFrame);
76
77
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
78
f.setSize(dim.width/6, dim.height/5);
79
textFrame.setBounds(10, 10, dim.width/8, dim.height/8);
80
81
textFrame.setVisible(true);
82
83
JButton b1 = new JButton("Hit me 1");
84
b1.addActionListener(new ActionListener() {
85
public void actionPerformed(ActionEvent e) {
86
JOptionPane.showInternalConfirmDialog(null, "Test?");
87
}});
88
89
JButton b2 = new JButton("Hit me 2");
90
b2.addActionListener(new ActionListener() {
91
public void actionPerformed(ActionEvent e) {
92
JOptionPane.showInternalConfirmDialog(new JInternalFrame(), "Test?");
93
}});
94
95
textFrame.setLayout(new FlowLayout());
96
textFrame.add(b1);
97
textFrame.add(b2);
98
f.setVisible(true);
99
}
100
}
101
102