Java: Créer une boîte de dialogue Modale.

Author:


{filelink=845}


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

public class BoiteModal {
  public static void main(String args[]) {
    final JFrame frame1 = new JFrame("Gauche");
    final JFrame frame2 = new JFrame("Droite");
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton bouton1 = new JButton("Gauche");
    JButton bouton2 = new JButton("Droite");
    frame1.add(bouton1);
    frame2.add(bouton2);
    ActionListener listener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JButton source = (JButton) e.getSource();

        JOptionPane pane = new JOptionPane("Nouveau Label", JOptionPane.QUESTION_MESSAGE);
        pane.setWantsInput(true);
        JDialog dialog = pane.createDialog(frame2, "Taper un texte");

        dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
        dialog.setVisible(true);
        String text =  (String) pane.getInputValue();

        if (!JOptionPane.UNINITIALIZED_VALUE.equals(text) && text.trim().length() > 0) {
          source.setText(text);
        }
      }
    };
    bouton1.addActionListener(listener);
    bouton2.addActionListener(listener);
    frame1.setBounds(100, 100, 200, 200);
    frame1.setVisible(true);
    frame2.setBounds(400, 100, 200, 200);
    frame2.setVisible(true);
  }
}

A Voir sur le même Sujet:

  • boite modal java
  • dialog java
  • boite de dialogue modale en java
  • appel d'un jdialog a partir jframe java
  • Créer une boite de dialogue dans java
  • boite de dialogue
  • java boite modale
  • java boite dialogue modale
  • encodage boite dialogue java
  • listener

Leave a Reply

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