Java Reference
In-Depth Information
status.setText(INITIAL_STATUS);
this.pack();
// Center on screen
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((d.getWidth() - this.getWidth())/ 2);
int y = (int) ((d.getHeight() - this.getHeight())/ 2);
this.setLocation(x, y); this.setVisible(true);
}
When the user has entered all the valid information and clicked the Start Server button,
all the user fields and buttons with the exception of the Exit button are disabled, as shown in
Figure 8-36.
Figure 8-36. The running server GUI
This is achieved with the following code in the action listener for the Start Server button:
configOptionsPanel.setLocationFieldEnabled(false);
configOptionsPanel.setPortNumberEnabled(false);
configOptionsPanel.setBrowseButtonEnabled(false);
configOptionsPanel.setSocketOptionEnabled(false);
configOptionsPanel.setRmiOptionEnabled(false);
startServerButton.setEnabled(false);
We then add a shutdown hook to handle any exit events:
Runtime.getRuntime().addShutdownHook(new CleanExit());
Finally we start the appropriate server depending on what type of server the user has
chosen.
The shutdown hook code is very simpleā€”it is simply an initialized thread that gets called
when the application is shutting down. It locks the database so that no other thread can
attempt to write to the file while we are shutting down, and then exits. The complete code for
the shutdown hook is shown in Listing 8-32.
Search WWH ::




Custom Search