Source Code : Demonstrating Modality Types
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Demonstrating Modality Types
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DualModal {
public static void main(String args[]) {
final JFrame frame1 = new JFrame("Left");
final JFrame frame2 = new JFrame("Right");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button1 = new JButton("Left");
JButton button2 = new JButton("Right");
frame1.add(button1);
frame2.add(button2);
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
JButton source = (JButton) e.getSource();
JOptionPane pane = new JOptionPane("New label", JOptionPane.QUESTION_MESSAGE);
pane.setWantsInput(true);
JDialog dialog = pane.createDialog(frame2, "Enter Text");
// dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
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);
}
}
};
button1.addActionListener(listener);
button2.addActionListener(listener);
frame1.setBounds(100, 100, 200, 200);
frame1.setVisible(true);
frame2.setBounds(400, 100, 200, 200);
frame2.setVisible(true);
}
}
Thank with us