Chapter 3

Using the Developer Studio


CONTENTS

In this chapter you learn how to use the Microsoft Developer Studio. The Developer Studio is an integrated development environment that is designed to make a programmer's life easier. It includes tools and features for managing a project's source code and configuration setting and for visually designing its resources, an editor that understands Java and HTML syntax, and even an integrated debugger that can step through code executing in a browser. If you're familiar with Microsoft Visual C++, you've already met the Developer Studio, and you might want to skip ahead to Chapter 4 "Applet Programming Fundamentals."

What Is the Developer Studio?

The Developer Studio is a fully integrated development environment (IDE). From within the Developer Studio you can do anything you could possibly want to while developing a Java program. In the dark ages of programming, a programmer used to rely on a collection of different tools. (The "dark ages of programming" is defined as any period five years prior to the current date.) Each programmer had a separate editor, a compiler, a debugger, and other tools as necessary. With an IDE, not only are these tools collected into one environment but they also are designed to work together in order to improve the productivity of the programmer.

Figure 3.1 shows the Developer Studio while being used to develop example EX02B, which was built in Chapter 2 "Creating Your First Applet with Applet Wizard." In the figure the left portion of the screen displays the ClassView pane of the Project Workspace window. Also displayed are a source code editing window, a graphic image editing window, and an InfoView topic. The rest of this chapter is devoted to covering some of the key concepts in using the Developer Studio.

Figure 3.1 : Creating a new project workspace.

Understanding Workspaces

When programming in Visual J++, all your work is performed in a workspace. A Visual J++ workspace is a way of logically associating project source code and configurations for building that source code. For example, a typical workspace will define a project that is comprised of one or more Java source files and Debug and Release configuration settings that describe how to build the project.

As you saw in Figure 3.1, the Developer Studio features a Project Workspace window that is located prominently on the left of the Visual J++ desktop. The Project Workspace window is one of the most important in Visual J++ because it enables you to quickly navigate through a workspace's projects, classes, and files. It also provides easy access to online documentation through the InfoView. To consolidate all this information into one place, the Project Workspace window contains three panes of information-ClassView, FileView, and InfoView. Each of these panes is activated by selecting the tab at the bottom of the Project Workspace window.

Working with FileView

The FileView pane of the Project Workspace window enables you to view and work with the files in your projects. It is displayed as a hierarchical list box as shown in Figure 3.2. In this figure you can see that the project EX02B contains an HTML file, a pair of Java files, and then a series of GIF files. To select one of the files for editing, double-click the mouse over the desired filename. In Figure 3.2, the file EX02BFRAME.JAVA was selected in the FileView pane, and a window for editing it was displayed to the right of the Project Workspace.

Figure 3.2 : Using the FileView to edit a Java source file.

Because a project can contain files other than simple text files, such as source code, the Project Workspace lets you edit and display other file types. Figure 3.3 illustrates this by showing how a graphic image-a filenamed IMG0013.GIF-is displayed. As you can see in Figure 3.3, the image is shown at its actual size and at a magnified size. A palette of graphics editing tools is also provided.

Figure 3.3 : Using the FileView to edit a graphic file.

Using Dockable Windows

So far, the Project Workspace window has always been on the left side of the screen. The Project Workspace window, like many windows in Visual J++, is a dockable window. A window is dockable if you can move it into a position and have it become anchored in that position. When you do this, the window will usually reshape itself to dimensions appropriate for its new position.

Because the Project Workspace window is a dockable window, you can move it from its default home at the left of the Developer Studio. You can even undock it by moving it to the middle of the Developer Studio desktop where it becomes a free-floating window, as shown in Figure 3.4.

Figure 3.4 : Undocking the FileView by moving it to the middle of the Developer Studio desktop.

To move a dockable window, position the mouse pointer near the border of the window and hold the left mouse button down. While holding the mouse button down, begin moving the mouse. As you do, an outline of the window will move with you, changing shape as you move the window across the desktop. Once you've found a suitable location, release the mouse button and the window will move. You should experiment with various locations for the dockable windows until you've found an arrangement that suits your working style.

Working with ClassView

The ClassView pane of the Project Workspace window will probably be the one you'll use most frequently. (Looking at a project through its files is a somewhat artificial approach.) More useful is the capability to look at the classes that are used by a project and then to be able to see the methods and variables that are members of the classes. This is precisely what the ClassView enables you to do. The ClassView is shown in Figure 3.5.

Figure 3.5 : Using the ClassView to edit the getAppletInfo method.

Like the FileView, the ClassView can be used to open an edit window by double-clicking an item in the Project Workspace. In Figure 3.5, a double-click on the getAppletInfo method of the EX02B class has opened the edit window to the right of the Project Workspace window. A key difference between the FileView and the ClassView is that the ClassView has opened the Edit window and positioned it at the desired function. In this way, it is possible to use the ClassView to navigate a class without regard to the file in which the class is stored.

Adding Variables, Methods, and Classes

Throughout the Developer Studio of Visual J++, the right mouse button can be used to display a menu of actions relevant to the current context of the program. When working with the ClassView, you can highlight a class name and press the right mouse button. Doing so activates a menu that, among other things, lets the user add variables or methods to the highlighted class.

Adding Variables

To add a member variable to a class, select Add Variable from the context menu displayed when the right mouse button is clicked. This will display the dialog shown in Figure 3.6. On this dialog you can set the variable type, name, an initial value, and select the desired access modifiers.

Figure 3.6 : Creating a new String variable from the ClassView.

Adding Methods

It is just as easy to add a new method to a class as it is to add a new member variable. Select Add Method from the context menu, and the dialog shown in Figure 3.7 will appear. Here you can specify the return type of the method, its name, and any modifiers. After pressing the OK button, the appropriate source code is added to the class and the editor is positioned at the start of the new method. In the case of the method being added in Figure 3.7, the following code will be added to the class:

private static String myMethod() 
{
}

Figure 3.7 : Creating a new method from the ClassView.

Adding Classes

Finally, it is also possible to create a new class from the ClassView pane of the Project Workspace. From the context menu you can select Create New Class to be presented with the Create New Class dialog as shown in Figure 3.8.

Figure 3.8 : Creating a new class from the ClassView.

To create the new class, press the OK button. This will create a new class in the ClassView and a new File in the FileView. If you were to move to the new class in the ClassView, you could then continue using the ClassView to add the appropriate methods and variables.

Working with InfoView

The final pane of the Project Workspace is the InfoView. The InfoView is used to view the online books provided with Visual J++. Included with Visual J++ are online books such as a User's Guide, a two-volume API (Application Programming Interface) reference, a Test Drive book introducing Visual J++, and other reference books. The InfoView provides a very powerful viewer for these online books. The InfoView as it appears when viewing the java.awt package is shown in Figure 3.9.

Figure 3.9 : The InfoView while reading about the java.awt package.

Opening Books

To use the InfoView, highlight the book you are interested in and continue opening chapters in it until you find a page display. In Figure 3.9, the chapter java.awt within the book Java API, Volume 2 has been opened. Within that chapter, a page titled "Package java.awt" has been selected in the InfoView pane and the contents of the page have been displayed in a window to the right of the InfoView.

Searching

If you know what you want to read and where it's located, opening a book and moving to the page can be a very quick way to get to the information you need. However, usually you don't know where to find what you need to know. In these cases, you need to search the online books. You can use the InfoView to search either by topic or for any word in the full text. To search, click the right mouse button while the mouse pointer is over the InfoView or select the search button from the standard toolbar. Doing so will display the Search dialog as shown in Figure 3.10.

Figure 3.10 : The Index page of the InfoView Search dialog.

If when searching by topic you don't find what you're looking for, you can select the Query page of the Search dialog, as shown in Figure 3.11. Doing so will enable you to enter one or more words to be searched for. You can search the entire set of books or limit the scope of the search to a particular topic or a subset of topics.

Figure 3.11 : The Query page of the InfoView Search dialog.

Working with Projects

You've already seen how the Project Workspace window organizes a project's files and classes into an easy-to-navigate structure. However, files and classes are only part of a project. In addition to the files that comprise a project, the Developer Studio also organizes the configuration settings you use when building a project.

Configuring Projects

Each project must be associated with at least one configuration. The configuration indicates how the project will be compiled (optimization, output directories, compiler options, and so on) and how it will be run from the Developer Studio. A project can be run as a stand-alone application or under the control of a browser. If under a browser, the configuration can specify the filename of the browser and any options needed to run it.

A typical Visual J++ project will include two configurations: one for creating a debuggable version and a second for creating a releasable version. If you use the Applet Wizard to create your project, it will create these two configurations for you. Each project will have a default configuration. You can set the default configuration by selecting Set Default Configuration from the Build menu.

You can manage a project's configurations by selecting Configurations from the Build menu. This will activate the Configurations dialog, as shown in Figure 3.12.

Figure 3.12 : The Configurations dialog.

You can add or remove configurations using the Configurations dialog. To add a new configuration, select the Add button. This will display the Add Project Configuration dialog, as shown in Figure 3.13.

Figure 3.13 : The Add Project Configuration dialog.

To edit the configuration settings, select Settings from the Build menu. This will display the General page of the Project Settings window as shown in Figure 3.14. In addition to this page, the Project Settings dialog contains pages for setting Debug and Java options. These pages are shown in Figures 3.15 and 3.16.

Figure 3.14 : The General page of the Project Settings dialog.

Figure 3.15 : The Debug page of the Project Settings dialog.

Figure 3.16 : The Java page of the Project Settings dialog.

Additionally, the Debug page contains a list box named Category that allows you to set general debugging options, browser-specific debugging options, and stand-alone interpreter specific debugging options.

Working with Subprojects

Sometimes you are working on a set of related programs that are built and released together. For example, you might be developing an applet that will let World Wide Web users order items from your store. The applet displays a searchable list of available items and lets users examine each item and select some for purchase. Although all items are displayed, only items that are in stock can be purchased. You are writing a second applet to manage inventory levels that lets an inventory receiving clerk update the database as new items are received.

Clearly, these two applets have much in common and, if designed correctly, would share some common classes. The Visual J++ Developer Studio facilitates working on two related projects by enabling you to include subprojects in the Project Workspace. To create a new subproject, select Subprojects from the Build menu and select the New button. The Insert Project dialog, as shown in Figure 3.17, will be displayed.

Figure 3.17 : The Insert Project dialog.

This dialog should look familiar because it is similar to the New Project Workspace dialog you've already used. However, on the Insert Project dialog you can specify whether the new project is a top-level project or is subproject of an existing project in your workspace.

Setting the Default Project

Many Visual J++ operations are performed on the default project. The default project is always based on the default configuration. Earlier in this chapter you learned that you can set the default configuration by selecting Set Default Configuration from the Build menu. The default project is indicated in bold text in the FileView and ClassView panes of the Project Workspace window.

Building a Subproject

There are three ways you can build a subproject. These are as follows:

  1. Make the project the default project and select Build from the Build menu.
  2. Select Rebuild All from the Build menu.
  3. Select Batch Build from the Build menu, and select the projects and configurations you want to build.

Removing a Project

Sometimes a project outlives its usefulness. To remove a project from the Project Workspace, select Configurations from the Build menu, highlight the desired project, and press the Remove button. You will be asked to confirm that you want to remove the project before it is deleted from the Project Workspace.

Summary

This chapter showed you how to use the Developer Studio. You learned about project workspaces, and how to manage multiple projects and configurations within a single workspace. You saw how to use the FileView, ClassView, and InfoView panes of the Project Workspace window to navigate through the files and classes of your projects. Using the ClassView, you learned how to let Visual J++ help you create new classes and add methods and variables to existing classes. Now that you're comfortable with the Developer Studio, you're ready for the next chapter where you'll learn the fundamentals of applet programming.