Name: skT88420 Date: 07/23/99
Modal dialog does not block input to non-modal dialog if the modal dialog is shown first.
The following code:
- Creates 2 independent frames and shows
- Creates a non modal dialog and kicks off a thread to show the dialog in 10 seconds time.
- Creates a modal dialog and shows it
Note that mouse events are printed to the console when the mouse is moved over either of the dialogs. This is wrong, a modal dialog should block all input to non-child windows in the same AppContext.
import java.awt.*;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseEvent;
public class DialogBug implements Runnable {
Frame modalParentFrame, nonModalParentFrame;
Dialog modalDialog, nonModalDialog;
public DialogBug() {
// create an independent top level frame to be the
// parent of the modal dialog and show it
modalParentFrame = new Frame("Parent of modal dialog");
modalParentFrame.setBounds(100,100, 200, 200);
modalParentFrame.addMouseMotionListener(new DebugAdapter() );
modalParentFrame.setVisible(true);
// create an independent top level frame to be the
// parent of the non-modal dialog and show it
nonModalParentFrame = new Frame("Parent of non-modal dialog");
nonModalParentFrame.setBounds(400,100 , 200, 200);
nonModalParentFrame.addMouseMotionListener(new DebugAdapter() );
nonModalParentFrame.setVisible(true);
// create the non-modal dialog and kick off a
// thread to show it in 10 seconds time
nonModalDialog = new Dialog(nonModalParentFrame, "Non modal", false);
nonModalDialog.setBounds(400, 400, 100, 100);
nonModalDialog.addMouseMotionListener(new DebugAdapter() );
new Thread(this).start();
// create the modal dialog and show it from this thread
modalDialog = new Dialog(modalParentFrame, "Modal", true);
modalDialog.setBounds(100, 400, 100, 100);
modalDialog.addMouseMotionListener(new DebugAdapter() );
modalDialog.setVisible(true);
}
public static void main(String [] args) {
new DialogBug();
}
// This is the implementation of Runnable and is
// used to show the non-modal dialog in 10 seconds
public void run() {
try {
Thread.currentThread().sleep(10 * 1000);
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
//show the non modal dialog
nonModalDialog.setVisible(true);
}
}
class DebugAdapter extends MouseMotionAdapter {
public void mouseMoved(MouseEvent e) {
System.out.println(e);
}
}
(Review ID: 88324)
======================================================================