About Modal Forms
Only JDialog in Swing can be set to a Modal form, whose methods can be passed in a constructor (such as "JDialog (Frame owner, Boolean Modal)"), or by using the Setmodal (Boolean) method, which A method is inherited from the Dialog class.
In the JFrame class, the Modal form cannot be set through a method such as JDialog, where a friend tries to simulate a windowdeiconified form by Requestfocus () at Modal (), as follows:
public class Mymodalframe extends JFrame implements WindowListener ... {
Private JFrame frame = null;
Private Boolean modal = false;
Private String title = null;
Public mymodalframe () ... {
This (null, false);
}
Public Mymodalframe (JFrame frame) ... {
This (frame, false);
}
Public Mymodalframe (JFrame frame, Boolean modal) ... {
This (frame, modal, "");
}
Public Mymodalframe (JFrame frame, Boolean modal, String title) ... {
Super (title);
This.frame = frame;
This.modal = modal;
This.title = title;
This.init ();
}
private void init () ... {
if (modal)
Frame.setenabled (false);
This.addwindowlistener (this);
}
public void windowopened (WindowEvent windowevent) ... {
}
public void windowclosing (WindowEvent windowevent) ... {
if (modal)
frame.setenabled (true);
}
public void windowclosed (WindowEvent windowevent) ... {
}
public void windowiconified (WindowEvent windowevent) ... {
}
public void windowdeiconified (WindowEvent windowevent) ... {
}
public void windowactivated (WindowEvent windowevent) ... {
}
public void windowdeactivated (WindowEvent windowevent) ... {
if (modal)
This.requestfocus ();
}
}