Galera, tenho esse JOptionPane que aparece em eventos de botão da aplicação. Porém, se eu clicar 100 vezes no votão da aplicação, abre 100 novos JOptionPane… Como faço para que esse JOptionPane receba o foco e só libere a aplicação para uso quando for clicado em seu botão ou quando for fechado? Segue o código…
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class WarningMessage01 extends JPanel implements ActionListener{
JPanel painel;
JButton ok, cancel;
public void inicializa(){
painel = new JPanel();
ok = new JButton("OK");
ok.addActionListener(this);
cancel = new JButton("CANCEL");
cancel.addActionListener(this);
painel.add(ok);
painel.add(cancel);
add(painel);
}
public static void main(String[] args){
JFrame frame = new JFrame("Testando o foco no warning message");
WarningMessage01 master = new WarningMessage01();
master.inicializa();
frame.setContentPane(master);
frame.setSize(600, 600);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String event = e.getActionCommand();
if (event == "OK"){
JOptionPane.showInternalOptionDialog(this,
"Você apertou o botão OK",
"Testando focus na mensagem interna",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE,
null, null, null);
} else if (event == "CANCEL"){
JOptionPane.showInternalOptionDialog(this,
"Você apertou o botão CANCELAR",
"Testando focus na mensagem interna",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE,
null, null, null);
}
}
}