Chapter 9

Managing Visual J++ Projects

by Bryan Morgan


CONTENTS

The Developer Studio Integrated Development Environment (IDE) is used by Visual J++, as are Microsoft's Visual C++ and FORTRAN PowerStation development tools. Whereas earlier chapters focus on the usage and configuration of the development environment as a whole, this chapter covers Visual J++ projects in detail. The project workspace, in particular, is presented as a tool for managing complex Java development projects.

Thus far, all of this book's material on the Visual J++ environment has dealt with creating and modifying text files containing Java source code. These files are compiled to produce Java bytecode within Java.class files. If the editor were the only feature of Visual J++, it probably would have been named simply J++ (or even J-imagine that!) However, Visual J++ gives the Java developer a full complement of visual development tools that can be used to build graphical user interface (GUI) objects using a variety of components. The standard visual elements of the World Wide Web, GIF, and JPEG files can also be created using the Visual J++ graphics editor. This chapter examines the graphics editor and other Visual J++ resource development tools.

Visual J++ Project Workspaces

Visual J++ uses project workspaces to allow developers to group related parts of a project into a single area of work, or workspace. Each project workspace must contain at least one Java project, although it can contain more if necessary. Java source files are contained in each of these main Java projects. Each of these main projects can also contain multiple subprojects, which can contain a Java project or even a project written in another language. (In this case, Java native methods would be used to access code in the subproject.) Within each of these projects is a set of files. These files can be Java source code files, readme documentation files, or even native code used to build Windows dynamic link libraries (DLLs) that your Java application can use.

Project workspaces are also used to maintain configuration information about a Java project. Information typically maintained in a project workspace includes compilation switches, file or class path locations, class file output locations, and compilation settings (such as Debug or Release). These settings are presented in this chapter. However, for more specific information about compiler options, see Chapter 10, "The Visual J++ Compiler."

Quite often, users of Visual J++ use the words project and project workspace interchangeably. This is because project workspaces commonly contain only one project. However, the capability to add multiple projects with associated multiple subprojects allows a developer to visually group together an extremely large set of related files. The Rebuild All command can even be used to rebuild all these projects at once to ensure that the latest version of your application is being released.

Creating Project Workspaces

You can use two methods to create a default project workspace: open an existing Java source file and compile it, or manually create a project workspace by selecting the appropriate option in Visual J++.

Creating a Workspace Using Existing Source Code

Perhaps you have been developing in Java using Sun's Java Developer's Kit (JDK). The JDK comes with a command-line compiler, debugger, and interpreter that can be used to build Java applications. Of course, because these tools are command line only, they lack many of the sophisticated visual capabilities found in Visual J++. However, until recently, many beginning developers used the JDK as their primary Java development tool because it worked and it was free. Let's assume you used the JDK previously to build the sample application found in Listing 9.1. Now that you have bought a version of Visual J++, you would like to use it to compile and build the application from now on.


Listing 9.1. A standalone Java class.

class Example1

{

  String Chapters[] = 

  {

    "Chapter 1:  Visual J++:  What It Is and Why It Is Special,"

    "Chapter 2:  Understanding the Java Runtime Environment,"

    "Chapter 3:  Object-Oriented Programming with Java,"

    "Chapter 4:  Understanding the Java Base Platform,"

    "Chapter 5:  Elements of the Java Language,"

    "Chapter 6:  Creating Programs with Java,"

    "Chapter 7:  Advanced Java Programming,"

    "Chapter 8:  Developing Applets and Applications,"

    "Chapter 9:  Managing Visual J++ Projects,"

    "Chapter 10:  The Visual J++ Compiler,"

    "Chapter 11:  Building a Simple Applet with Visual J++,"

    "Chapter 12:  Debugging with the Visual J++ Debugger,"

    "Chapter 13:  The Standard Java Packages,"

    "Chapter 14:  An Introduction to GUI Programming,"

    "Chapter 15:  GUI Development Using the Visual J++ Resource Wizard"

  };



  public static void main(String args[])

  {

    Example1 demo = new Example1();

    demo.Completed(8);

  }



  void Completed(int Number)

  {

    for (int i = 0; i <= (Number - 1); i++)

    {

      System.out.println(Chapters[i]);

    }

  }

}


When this Java file is opened in Visual J++, it loads like a normal Java source file; all the editor features such as syntax highlighting and automatic tabbing are enabled. However, when Visual J++ tries to compile the file, it looks for the file's associated project workspace. Finding none, it prompts the user to determine if he wants to create a default project workspace to be associated with this Java source file (see Figure 9.1).

Figure 9.1 : Creating a default project workspace.

It is impossible to compile a Java class within Visual J++ without the presence of a project workspace. Therefore, if No is selected in the dialog box in Figure 9.1, nothing happens.

NOTE
Keep in mind that nothing will physically happen to your .java source code or .class bytecode files if a project workspace is created. These files can still be used by any other Java compiler on any platform. Making a project workspace simply creates a set of additional files used by Visual J++ to maintain project configuration information.

After the project workspace has been created and the class has been compiled, the ClassView, FileView, and InfoView tab screens are available and loaded with your new project workspace (see Figure 9.2).

Figure 9.2 : The Java class loaded into the new workspace.

Notice that the ClassView shown in Figure 9.2 already contains the methods and variables contained in the Example1 class shown in Listing 9.1. For the record, a few additional actions must be accomplished before the Example1 class can be run. Selecting Build|Execute will cause another dialog box to be shown the first time this class is run. Because this is a Java application, not an applet, select Stand-alone interpreter and enter the class name to be run (Example1, in this case). Running this example should produce the following output:


Chapter 1:  Visual J++:  What It Is and Why It Is Special

Chapter 2:  Understanding the Java Runtime Environment

Chapter 3:  Object-Oriented Programming with Java

Chapter 4:  Understanding The Java Base Platform

Chapter 5:  Elements of the Java Language

Chapter 6:  Creating Programs with Java

Chapter 7:  Advanced Java Programming

Chapter 8:  Developing Applets and Applications

Examining the directory where the Example1.java file was located reveals that the following files were created as part of the project workspace:

Example1.mdp-The project workspace file
Example1.mak-The project makefile
Example1.ncb-The project information file

Now that all your existing Java source files have been imported into Visual J++ and project workspaces have been created, in the future you will most likely create new project workspaces from scratch.

Creating a Workspace from Scratch

New project workspaces can also be created using the File|New menu option. Selecting this option will bring up the New dialog box, which gives the user the option of creating a new source file, project workspace, bitmap, or resource template. Selecting Project Workspace brings up the dialog box shown in Figure 9.3.

Figure 9.3 : The New Project Workspace dialog box.

For now, select New|Project Workspace. (The Java Applet Wizard is discussed in detail in Chapter 11, "Building a Simple Java Applet with Visual J++.") Enter the directory in which the project workspace should be created and the name of the new workspace. If a directory does not already exist with the name of the new workspace, a new directory, containing the workspace .mak and .ncb files, will be created for you. By default, the project workspace is created with no member files. Therefore, to do anything useful, you must add new files. Existing files can be added to any project manually, and new files can be added using tools available in Visual J++.

Adding Existing Files to a Project

After copying the Example1.java file into the Example2 directory, this file and any others can easily be added to the Example2 project: Simply choose the Insert|Files Into Project menu and select whichever files you would like to add. Note that these files do not need to exist within the project directory. (The Example1.java file was added to the Example2 directory simply to avoid confusion.) Table 9.1 shows the file types that can be filtered and added using this dialog box.

Table 9.1. Visual J++ file types and descriptions.

File TypeDescription
*.javaJava source files
*.rc, *.rct, *.res Resource files
*.mak Makefiles
*.bmp, *.dib, *.jpg, *.gif, *.ico, *.cur Image files
*.exe, *.dll, *.ocx Executable files and libraries
*.bscBrowse info files
*.odlObject description libraries
*.libLibrary files
*.objObject files

After a file has been added, it can be viewed in the FileView control under the project name.

insertimageWARNING
The Insert|Files Into Project option is very different from the Insert|File option. Whereas Insert|Files Into Project results in the selected files being added to the currently selected project, Insert|File adds the contents of the selected file at the cursor location in the currently selected source code window.

After the desired files have been added to the project, they can be edited, compiled, or run in Visual J++ using the editor, compiler, and standalone interpreter or Web browser.

Creating New Files for a Project

Assuming that you really like Visual J++ and have made it your tool of choice for Java development projects, more often than not you will create new files within a project (rather than adding existing files). Visual J++ provides several ways of adding files to a project.

If the file is not a Java source code file and was created using another application, simply insert the file into the project using the Insert|Files Into Project menu option. If the file to be created is a Java source file, there are two options:

The first method has already been demonstrated, so let's add a new Java class by right-clicking the Example2 project. Doing so produces the dialog box shown in Figure 9.4.

Figure 9.4 : The Create New Class dialog box.

This is the preferred option because filling in the appropriate options in the dialog box creates a skeleton class with the appropriate keywords. Filling in the dialog box with the options shown in Figure 9.4 creates the class in Listing 9.2 and adds it to the Example2 project.


Listing 9.2. The Example2 class generated by Visual J++.

import Example1;



/*

 *

 * Example2

 *

 */

public class Example2 extends Example1

{





}


After this class has been added to the project, right-clicking it in the ClassView page of the project workspace will produce a pop-up menu. Within this menu are options to add methods (Add Method) and variables (Add Variable) to the class.

Adding Methods to a Class

Clicking the Add Method pop-up menu option produces the dialog box shown in Figure 9.5. Selecting OK for all the options shown in Figure 9.5 modifies Example2.java as shown in Listing 9.3.

Figure 9.5 : The Add Method dialog box.


Listing 9.3. The method added by Visual J++.

import Example1;



/*

 *

 * Example2

 *

 */

public class Example2 extends Example1

{

  public int GetGoing(boolean StartUp) 

  {

  }

}


The getGoing() method is added with the signature specified in the Add Method dialog box.

Adding Variables to a Class

Clicking the Add Variable pop-up menu option produces the dialog box shown in Figure 9.6. Selecting OK for all the options shown in Figure 9.6 modifies Example2.java as shown in Listing 9.4. The variable StartUp was added to the Example2 class using the Add Variable dialog box shown in Figure 9.6.

Figure 9.6 : The Add Variable dialog box.


Listing 9.4. The variable added by Visual J++.

import Example1;



/*

 *

 * Example2

 *

 */

public class Example2 extends Example1

{

  public static boolean StartUp = false;



  public int GetGoing(boolean StartUp) 

  {

  }

}


Adding and Using Subprojects

As mentioned earlier, a project workspace can contain multiple projects, and each of these projects can contain multiple subprojects. This allows the developer to create a project containing a reusable library of classes (such as the Politics package created in Chapter 6, "Creating Programs with Java," or a DLL that is called using native methods). The contents of these subprojects are immediately available to the developer, and all the projects and subprojects can be rebuilt at any given time using the Build|Rebuild All menu option. This ensures that the latest versions of all projects and subprojects are used when building an application or applet.

To add a subproject to an existing Visual J++ project, select the Insert|Project menu option. A dialog box similar to that shown in Figure 9.3 comes up. However, this dialog box gives the user the option of creating either a new top-level project or a subproject under an existing project (see Figure 9.7).

Figure 9.7 : Inserting a new project or subproject.

Entering Example2a into the dialog box and selecting a subproject to be created under Example2 creates the Example2a directory under the Example2 directory. Because no source files have been created or added to this new subproject, the directory and associated ClassView and FileView entries under Example2a are empty. (To add files or new Java classes to this subproject, follow the procedures described in the section "Creating New Files for a Project.")

Setting the Default Project

When multiple projects are available in a project workspace, it is important to know which one is the default project; in Visual J++, the default project's name appears in bold text and all other projects' and subprojects' names appear in normal text. Whenever a file is added to a project or the Compile/Build command is selected, these operations will take place on the currently selected default project. To set a project as the project workspace's default, right-click the project's name in the workspace's FileView and select the Set As Default Project option. This project's name will then appear in bold text and Visual J++ will use it as the default.

Deleting Projects or Subprojects from the Workspace

One not-so-obvious operation that you may need to perform from time to time is deleting a project from the workspace. This operation is nowhere to be found in all the menu options in Visual J++. However, it is possible to remove a project or subproject from a project workspace by selecting the Build|Configurations menu option. When chosen, the dialog box shown in Figure 9.8 appears.

Figure 9.8 : The Configurations dialog box.

To remove a project or subproject such as Example2 from the project workspace, select it in this dialog box and then press the Remove button. This will cause this project/subproject to be completely removed from the current project workspace. Files and directories associated with this project will not be physically removed from your hard drive, however.

Setting and Using Project Configurations

Each Visual J++ project is created, by default, with two project configurations associated with it: Debug and Release. Carefully examining these project configurations will show that the only difference between them lies in the configuration build settings for the compiler. The Debug configuration uses the /g switch with Generate Debug Info selected, and the Release configuration uses the /O switch with Full Optimization selected.

A project configuration provides an easy way to group a set of related compiler and environment settings together, which can be collectively used to control the final output of the compiler. In many cases, the Debug and Release settings may be adequate. However, many developers like to fine-tune the compiler settings to generate additional information or maintain more control over the compiler's output. (These settings are discussed in Chapter 10.)

To create a new project configuration, select the Build|Configurations menu option. The dialog box shown in Figure 9.8 appears. Now click on the Add button to display the dialog box shown in Figure 9.9.

Figure 9.9 : Adding a new project configuration.

Although this dialog box does not allow you to actually specify the settings for the new configuration, it does allow you to copy settings from an existing configuration. It is assumed that future versions of Visual J++ will allow more presetting of configuration options at this stage to reduce the number of steps required to add a new configuration. At any rate, after the new configuration has been added, you can modify its options by selecting the Build|Settings menu option.

Specifying the Default Project Configuration

To set a project configuration to be used as the default for future builds of the current project, select the Build|Set Default Configuration options. A dialog box appears (see Figure 9.10), asking the user to select the configuration to be used as the default.

Figure 9.10 : Setting the default configuration.

Selecting Example2-Java Virtual Machine Debug in this example results in the Example2 "Debug" configuration being used whenever this project is built.

Setting Workspace Display Options

In addition to setting the individual project and file settings associated with a project workspace, the actual display of the project workspace can be customized by selecting the Tools|Options menu option and then the Workspace tab (see Figure 9.11).

Figure 9.11 : Configuring workspace display options.

In this dialog box, the display of the following toolbars can be toggled:

Output
Watch
Variables
Registers
Memory
Call Stack
Disassembly
Project Workspace
InfoViewer Topic

Toggle any of these toolbars or select any of the additional options being displayed to make these changes globally for all project workspaces opened in the future. At this time, Visual J++ does not associate display changes with a specific project. Instead, it is assumed that a user feels most comfortable working within one specific environment and that this environment should apply to all project workspaces opened within Visual J++. (This philosophy differs from the IDE of Delphi, which can be customized on a project-by-project basis.)

Thus far, this chapter and this book deal extensively with the views available in the Developer Studio IDE (namely the ClassView, FileView, and the InfoView tab pages). Chapter 3 "Object-Oriented Programming with Java," introduces these views, and they are reintroduced here now that you are more familiar with Visual J++, the Java language, and project workspaces.

Working with the Developer Studio Views

Each view in the Developer Studio IDE gives you a different view of valuable project information. This information is available at the click of one button and can be relocated anywhere on the screen because these views are contained in "dockable" windows. This section discusses each option available in each view. Note that which options are available depends on which item is selected within one of the views. For instance, different options are presented to the user when a project is selected in ClassView than when a class is selected in ClassView.

At a minimum, right-clicking any of the views presents four options that apply to all views:

These primary options apply to each pop-up menu displayed in the project workspace window. The following sections discuss options that are specifically available in the ClassView, FileView, and InfoView pages.

The ClassView Options

The ClassView tab page allows you to view information about projects within the workspace and, specifically, about the Java classes available within those projects. Right-clicking a member in the ClassView page displays a pop-up menu. Table 9.2 lists the menu options available in the ClassView page and their meanings.

Table 9.2. ClassView menu options.

ItemMenu Option Meaning
Project nameCreate New Class Create a new class within the project
Class nameGo To Definition Open class file in text editor
Class nameAdd Method Add a method to the class
Class nameAdd Variable Add a variable to the class
Class nameCreate New Class Create a new class within the project
Class nameGroup By Access Group classes by access (public, protected, private, and so on)
Method nameGo To Definition Go to method within source file
Method nameSet Breakpoint Set debugging breakpoint at method
Method nameGroup By Access Group methods by access (public, protected, private, and so on)
Variable nameGo To Definition Go to variable within source file
Variable nameGroup By Access Group variables by access (public, protected, private, and so on)

The ClassView options apply specifically to Java classes. Note that ClassView's contents are updated immediately whenever classes are added, modified, or deleted; in other words, it is not necessary to wait for a class to be compiled to see the contents of ClassView updated.

The FileView Options

Whereas the ClassView page shows only information about Java classes, the FileView page shows information about all files contained in the current project, whether they are Java source files, graphics files, HTML files, documentation, or any other file associated with a project. Table 9.3 lists the options available when the pop-up menu is displayed over a specific FileView item.

Table 9.3. FileView menu options.

ItemMenu Option Meaning
Project nameBuildBuilds the project using the current configuration
Project nameSet As Default Project Sets the project as the workspace default
Project nameSettings Displays the Project Settings dialog box
Project workspace filenameSettings Displays the Project Settings dialog box
FilenameOpenOpens the file in an editor window
FilenameSettingsDisplays the Project Settings dialog box
Java source code Compile filename Compiles the selected file

In summary, FileView displays all the files (no matter what their type) within the project workspace. Double-clicking any one of the files opens it within an editor window. If the file is a graphics file (for example, *.bmp, *.gif, *.jpg), the graphics editor is opened. If the file is an HTML or Java source file, the standard Visual J++ editor is opened.

The InfoView Options

The InfoView page is different from the ClassView and FileView pages in that it contains information that applies to all project workspaces in Visual J++. (Even when a project workspace has not been opened, the InfoView page is still shown by default.) The InfoView page is used to display all available information (for example, documentation, help files, samples) that comes packaged with Visual J++. The Visual J++ 1.0 Professional Edition includes the following topics in the InfoView page:

Like in the FileView and ClassView pages, right-clicking any item in the InfoView page will bring up a pop-up menu. Table 9.4 lists the options available for each InfoView item.

Table 9.4. InfoView menu options.

ItemMenu Option Meaning
Any InfoView topicSearch Search or query InfoView topics for information
Any InfoView topicDefine Subset Filter the contents of the help system to display a subset
Any InfoView topicSet Default Subsets Define the default subsets to be used as Query, InfoView, and Context-Sensitive Help
Any InfoView topicPrint Print the selected InfoView topic

Including documentation in the InfoView page provides a handy reference point for an extremely large amount of information. Language, environment, and general Java information topics are within a few clicks of the mouse using the InfoView page.

Summary

With the Developer Studio IDE, Visual J++ allows developers accustomed to working with Microsoft's Visual C++ and FORTRAN PowerStation products to reuse the same environment when programming in Java. All Visual J++ projects are viewed and maintained using a project workspace, which contains project configuration settings and the contents of all projects in the project workspace. A project workspace can contain multiple projects, and each of these projects can contain multiple subprojects.

These projects and subprojects can be located anywhere on the file system (not just in the project workspace directory) and can contain development projects written in languages other than Java. For instance, you could create a subproject containing the information and files needed to build a new DLL used by a Java application. Selecting Rebuild All will rebuild all the projects and subprojects in the project workspace.

The contents of a project workspace can be examined and modified easily using the ClassView, FileView, and InfoView tab pages in the Project Workspace window. ClassView contains information about each class in each project (including class member method and variable information). New methods and variables can be added to a class using pop-up menu options. The FileView page contains information about each file within each project in the project workspace. Files of any type can be added and removed from the ListView (including graphics, HTML, and documentation files). The InfoView page contains Visual J++ and Java documentation topics and help information. All InfoView topics can be searched for information based on a user-defined query. For more information on user-defined queries, consult the Visual J++ documentation.

Visual J++ provides a refined GUI for project management functions and includes convenient help windows and wizards that can automate many routine tasks that otherwise would be done by hand (and therefore would be prone to error). Chapter 10 introduces the Visual J++ compiler and its settings. Although Visual J++ generates projects with default build settings of Release and Debug, these compiler settings may be useful to the developer wishing to adjust the compiler to accomplish a specific task.