Download NetBeans!

20070426 Thursday April 26, 2007

Building a Login Screen for a NetBeans Platform Application (Part 1)

Since the resolution of issue 92570, it is possible to show a modal dialog after the appearance of an application's splash screen, but before the appearance of an application's main window. And what would one want to put there? A login screen, of course. With this enhancement, it is possible to integrate some level of authentication into your NetBeans Platform application.

The specific method in question here is DialogDisplayer.notifyLater, which can now also be called before the main window is opened. When called from ModuleInstall.restored, the modal dialog is opened and blocks the main window until the modal dialog is closed. So, to implement this, use the Module Installer wizard, which will create a class that extends ModuleInstall (and adds relevant entries in the project.xml file and manifest file). You get a skeleton restored method for free. Fill out the method as follows:

public void restored() {
   NotifyDescriptor nd = new NotifyDescriptor.Message("Ok");
   DialogDisplayer.getDefault().notifyLater(nd);
}

You will now get a simple modal dialog, after the splash screen, where you must click OK before the main window of the application can open. See further examples in the Javadoc for Class NotifyDescriptor.

However, you can also create your own JPanel and return that in the above code, instead of "Ok". So, here's my new code:

LoginForm form = new LoginForm();
    
public void restored() {
   NotifyDescriptor nd = new NotifyDescriptor.Confirmation(form,"Login");
   DialogDisplayer.getDefault().notifyLater(nd);
}

And your LoginForm could be anything here. Mine looks like this:

It could be wired up to a database, with logic in the panel for verifying the password. So, the key to all of this is the fact that it is a modal dialog that appears after the splash screen and before the main window. Hurray!

Continue with part 2 of this series...

In other news. What?! Another new domain name in the NetBeans world? Yes. And it is... http://www.netbeans.tv/. Check it out! Hilarious adventures (e.g., "Today we’re discovering the hard way why Turkish beer is just not a morning’s best friend...") of two random American dudes from Prague delivering NetBeans IDE to some guy in Palestine who couldn't receive it by mail...

Apr 26 2007, 04:22:05 AM PDT Permalink