2
I was wondering, how can I know if a screen, in my case a JDialog
is open. Is there any event or way to know this?
Note: I will use this "information" as a parameter in a condition, for example, if closed screen does such a thing.
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class FecharTela extends JFrame {
private JButton botao = new JButton("+");
private DialogX x = new DialogX();
public FecharTela() {
setTitle("Teste");
add(montaTela());
setSize(500, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private JComponent montaTela() {
JPanel jpMontaTela = new JPanel();
jpMontaTela.add(botao);
botao.addActionListener((ActionEvent e) -> {
x.setVisible(true);
});
return jpMontaTela;
}
public static void main(String[] args) {
FecharTela ft = new FecharTela();
ft.setVisible(true);
}
}
class DialogX extends JDialog {
public DialogX() {
setSize(300, 300);
setLocationRelativeTo(null);
add(new JLabel("Erro no campo .."));
}
}