Java Reference
In-Depth Information
We then perform validation on the field the user has entered, setting the Boolean flag if
the user has entered valid data, as shown in the following code snippet for validating a field
name:
location = (String) optionUpdate.getPayload();
if (configOptions.getApplicationMode()
== ApplicationMode.STANDALONE_CLIENT) {
File f = new File(location);
if (f.exists() && f.canRead() && f.canWrite()) {
validDb = true;
log.info("File chosen " + location);
} else {
log.warning("Invalid file " + location);
}
}
Finally we check whether we have all the required fields, and if so, we enable the Connect
button as shown in the following code snippet:
boolean allValid = validDb && validPort && validCnx;
connectButton.setEnabled(allValid);
The Server GUI
The server GUI is shown in Figure 8-35. As can be seen, the majority of this GUI is the com-
mon panel developed earlier.
Figure 8-35. The server GUI
The constructor used to create the server GUI is shown in Listing 8-31. We start by setting
the title of the GUI, configuring the application to exit if the close button is clicked, and ensur-
ing the GUI cannot be resized.
We then create our menu bar the same way we did for the client application, and add our
ConfigOptions panel to the main window. We then add the buttons to start the server (disabled
until configuration options are set), and load any stored configuration options. Finally, we
center the server window on the screen, and set it to be visible.
Search WWH ::




Custom Search