Exemple de création d’une boîte de dialogue Modale

Author:


{filelink=846}

import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class DialogModal {

  public static void main(String[] args) {
    final JFrame parent1 = new JFrame("Frame de base");
    parent1.setLayout(new FlowLayout());
    parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton button = new JButton("Créer une dialogue Modale");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JDialog dialog = new JDialog(parent1, "Boite de dialogue Modale",
            Dialog.ModalityType.APPLICATION_MODAL);
        dialog.setBounds(200, 150, 200, 150);
        dialog.setVisible(true);
      }
    });
    parent1.add(button);
    parent1.setBounds(100, 100, 200, 150);
    parent1.setVisible(true);

    JFrame parent2 = new JFrame("Deuxiem Frame");
    parent2.setBounds(500, 100, 200, 150);
    parent2.setVisible(true);
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *