Starting and Stopping an Application

The com.ms.wfc.app package includes the static Application class, which takes care of all the Win32 window processing, such as registration, instantiation, handling the message loop, and so on. The main application window is created by calling the Application.run method and passing it your Form-derived object that makes up the visual aspect of the window. This call occurs in the main() method in the Form-based template class generated by Visual J++. The following code was generated for the MyNotepad application:

   public static void main(String args[])
   {
      Application.run(new MyNotepad());
   }

By default, the basic application created by a Visual J++ template is closed using the Window’s exit (X) button in the top-right corner of the application. However, you can programmatically quit the application anywhere in the code by calling the Application.exit method. For example, this application is closed when Exit on the File menu is clicked:

    private void FileMenuExit_click(Object sender, Event e)
    {
        // Call the new file handler to invoke NewDialog
        // to ask if user wants to save current data 
        this.FileMenuNew_click(sender, e);  
        Application.exit();
    }

Having described the code that is invoked when an application is run, it is worth mentioning how a user runs your application. Visual J++ has rich deployment features, one of which is to create a Windows executable (.EXE) file enabling users to run your WFC applications in a similar manner to other Windows application, assuming the WFC classes are installed on the user's computer. WFC classes are included with the latest Virtual Machine for Java which can be redistributed.