Database Reference
In-Depth Information
constructor uses reflection to instantiate a class of the type named, and will use that class in place of the
inner class of Login . This will rarely be used, but is needed in our security administration interface. We
have to become different applications in order to modify the associated connection strings. We will talk
about that in detail later in this chapter.
The JDialog class, which Login is extending, has a constructor that takes three arguments. You can
see our call to the JDialog constructor, super() . The last of those three arguments is a boolean that
designates whether the JDialog is modal. We set the modal boolean to true for the Login screen. We
want it to appear on top of whatever other screens are visible for the current application.
Note When calling other constructors, even super class constructors, those calls need to be the first line in the
calling constructor. That is why we needed an independent fourth constructor. We needed to instantiate a new
alternate inner class before we call the initialization methods. That could not have happened if we wanted to call
our original constructors to do initialization. That call to the original constructors would have to be done first.
The “Wait While Processing” Modal Dialog
In a GUI application, bad things can happen if a user is impatient and your application code is off doing
some complex calculation or data retrieval. The user may press a button repeatedly, possibly causing
your application's code to do a function multiple times; or the user may quit the application in
frustration. When your application is going to do something complex or possibly taking a long time, it is
best to put up a little notification in front of the application, letting the user know you are busy working
for them and asking them to be patient. Having described the complex list of tasks that take place in the
Login screen, you can understand why it might take a few moments to process, during which time we
will want the user to wait patiently.
I have defined a very simple JDialog class, sayWaitDialog , which I placed in the Login class.
sayWaitDialog is a static member of Login , and it is configured by a static initializer block. This dialog
screen is defined as a modal dialog—see the bold code in Listing 12-5. Modal dialogs appear on top of
other windows on the user's monitor, and they can't easily be hidden behind other windows, at least
those associated with the current application, even if the user clicks on other windows. I'm sure you
have seen and noticed that kind of behavior in other dialogs before.
Listing 12-5. Modal Dialog Asking User to Wait Patiently
public static JDialog sayWaitDialog = new JDialog();
static {
sayWaitDialog. setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) ;
sayWaitDialog.setModal(true) ;
sayWaitDialog.setTitle("Please Wait");
JPanel jPanel1 = new JPanel();
sayWaitDialog.setSize(new Dimension(255, 93));
sayWaitDialog.getContentPane().setLayout(null);
jPanel1.setBounds(new Rectangle(5, 5, 230, 45));
jPanel1.setLayout(null);
jPanel1.setBackground(new Color(255, 222, 214));
 
Search WWH ::




Custom Search