Как я могу закрыть одну JOptionPane при появлении другой JOptionPane в графическом интерфейсе

Как вы видели из моей темы выше,
{{1 }} Я хотел бы знать, как я могу отклонить JOptionPane, который стал неактуальным из-за другого JOptionPane и из-за того, что пользователь по какой-то причине не отклонил первый, нажав кнопку «ОК» (например).

Я видел на другом сайте подобный вопрос, и люди предлагали сделать просто:

JOptionPane.getRootFrame().dispose();  

Но как я могу сохранить ссылку для каждой имеющейся у меня JOptionPane и иметь возможность отклонять только то, что нужно.
Спасибо

Отредактировано:
Пример кода:

package Gui;

import javax.swing.JOptionPane;
import java.awt.*;

/**
 *
 * @author 
 */
public class JpanelMainView extends javax.swing.JPanel {

    /** Creates new form JpanelMainView */
    public JpanelMainView() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(149, 149, 149)
                .addComponent(jButton1)
                .addContainerGap(178, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(77, 77, 77)
                .addComponent(jButton1)
                .addContainerGap(200, Short.MAX_VALUE))
        );
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)                                         
    {                                             
       JOptionPane.showMessageDialog(this, "Board was sent for validation check\n Please wait...","Board Sent",JOptionPane.INFORMATION_MESSAGE);

       //Please note that this OptionPane is coming in my real program always after the first JoptionPane
       //I want that if I've reached the line in the code that need to show this second JoptionPane, I will first close the first JoptionPane
       //Else you will dismiss the last JoptionPane and then the first one and I don't want to give the user two JoptionPane to close, it's annoying.
       JOptionPane.showMessageDialog(this, "Set your move now please","Game started",JOptionPane.INFORMATION_MESSAGE);
    }                                        

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    // End of variables declaration                   

}
5
задан JavaSa 16 October 2011 в 22:24
поделиться