Path: blob/master/test/jdk/javax/swing/JOptionPane/7042497/JOptionPaneConfirmDlgTest.java
41153 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 704249725* @summary Verifies if JOptionPane.showInternalConfirmDialog26throws RuntimeException if parentComponent argument is null27* @run main/manual JOptionPaneConfirmDlgTest28*/2930import java.awt.Component;31import java.awt.Dimension;32import java.awt.FlowLayout;33import java.awt.Toolkit;34import java.awt.event.ActionEvent;35import java.awt.event.ActionListener;36import javax.swing.JButton;37import javax.swing.JFrame;38import javax.swing.JInternalFrame;39import javax.swing.JOptionPane;40import javax.swing.SwingUtilities;4142public class JOptionPaneConfirmDlgTest {43JInternalFrame textFrame;44JFrame f = null;4546public static void main(String[] args) throws Exception{47new JOptionPaneConfirmDlgTest();48}4950public JOptionPaneConfirmDlgTest() throws Exception {5152try {53SwingUtilities.invokeAndWait(()->createGUI());54Thread.sleep(10000);55} finally {56SwingUtilities.invokeAndWait(()->f.dispose());57}5859}6061public void createGUI() {62JOptionPane.showMessageDialog(63(Component) null,64"An internalFrame with 2 buttons will be displayed. \n" +65" Press \"Hit me 1\" button. The bug causes a RuntimeException to be thrown here\n" +66" But If a confirmation dialog comes, test has passed\n" +67" Similarly, press \"Hit me 2\" button. The bug will cause a RuntimeException\n" +68" to be thrown here but if a confirmation dialog comes, test has passed.\n" +69" Close the dialog and frame.",70"information", JOptionPane.INFORMATION_MESSAGE);71f = new JFrame();7273textFrame = new JInternalFrame("Main-Frame", true);74f.setContentPane(textFrame);7576Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();77f.setSize(dim.width/6, dim.height/5);78textFrame.setBounds(10, 10, dim.width/8, dim.height/8);7980textFrame.setVisible(true);8182JButton b1 = new JButton("Hit me 1");83b1.addActionListener(new ActionListener() {84public void actionPerformed(ActionEvent e) {85JOptionPane.showInternalConfirmDialog(null, "Test?");86}});8788JButton b2 = new JButton("Hit me 2");89b2.addActionListener(new ActionListener() {90public void actionPerformed(ActionEvent e) {91JOptionPane.showInternalConfirmDialog(new JInternalFrame(), "Test?");92}});9394textFrame.setLayout(new FlowLayout());95textFrame.add(b1);96textFrame.add(b2);97f.setVisible(true);98}99}100101102