First Look
A Visual Tour of the New Tool
By Brian Johnson
Visual J++ 6.0 (VJ6) excels in a number of areas where its predecessor fell short. Visual J++ 1.0 and 1.1 are essentially tools that make Java development practical in Microsoft Visual Studio using the same IDE that serves C++ developers so well. Visual J++ 6.0 lets you work in a nearly identical manner to the way you did in version 1.1 — if you wish, but it adds important features that Visual Basic programmers may find more familiar. These include IntelliSense technology, a RAD visual design environment, and a choice of packaging solutions that make application deployment a snap.
This article takes you on a tour of just a few of the new features of VJ6. It should provide enough information to give you a quick start with the new version.
So What's New?
The IDE for one thing. The IDE for VJ6 is shared with Microsoft Visual InterDev 6.0. The idea is that you should be able to easily move between Web page, Java, and script development. This is sound design and it works well. The interface seems designed for a screen resolution larger than 600x800, but you can change the layout of the environment to suit your needs.
The default layout for the IDE (see Figure 1) docks the program's Toolbox along the left-hand side of the main window. Along the right-hand side, you'll find the Project Explorer, which keeps your projects organized in an outline view. From here, you can access the properties for your projects and add and remove project files. Below the Project Explorer window, you'll find a Properties window that lets you choose between compiling, debug, and release versions of the selected project. For WFC applications (more about these later), this window gives you access to the properties and events of the controls you add to your forms.
Figure 1: The default layout of the Visual J++ 6.0 IDE.
The Task List. Another new interface feature is the Task List window. At first glance, this window seems to be just a reworking of the debugger window from Visual Studio. Actually, the Task List window provides additional capabilities that make managing projects much easier. In addition to listing error messages during project builds, the Task List lets you add your own tasks and shortcuts to code in the editor.
TODO, HACK, and UNDONE comments are automatically added to the Task List. As with the shortcuts, this makes it much easier to find areas in your code that still need work. The process is automatic. Just create a comment that starts with "TODO," and the TODO shortcut is added to the Task List. Make the first few words of the TODO comments short and meaningful. Double-clicking on the item takes you straight to that line of code in the editor (see Figure 2).
Figure 2: The new Task List makes it much easier to find areas in your code that need work.
The WFC. The biggest change for most Visual J++ developers is the addition of the Windows Foundation Classes (WFC). If you're not familiar with WFC, you can think of it as a sort of MFC for Java programmers. The WFC framework encapsulates the features of Win32 and Dynamic HTML. It provides the programmer with a set of controls for Java solutions designed to run on the Win32 platform. You'll find the WFC Designer components on the WFC Controls tab of the Toolbox window. (For more information about WFC, see the first two articles in this issue.)
Plenty of Wizards. With VJ6, Java developers now have a much greater range of targets for Java projects. In addition to standard applets and applications, you can now automatically target Java solutions as Windows executable files and COM controls. New Wizards and Builders in VJ6 walk you through the creation of new Java applications. The Application Wizard gives you a start with WFC forms-based applications. The Data Form Wizard lets you easily add data-bound forms to your project. The Class Builder automates some of the processes behind the creation of new classes. The Class Builder is especially useful if you're working on a COM class. Finally, the J/Direct Call Builder gives you easy access to the Win32 API through your Java application.
Because these new Wizards are key to getting a fast start with VJ6, let's discuss each of them in turn.
A New Project
The New Project dialog box contains the Wizards and templates available for the creation of VJ6 projects. Because the new IDE is shared with Visual InterDev (VI), you'll see options for creating VI projects along with your Java projects, if you have both programs, or Visual Studio 6 installed (see Figure 3). Let's select the Application Wizard and walk through the creation of a new WFC project.
Figure 3: The New Project dialog box.
Application Wizard. The first window displayed after you select the Application Wizard and name your project is the Welcome screen where you can select a previously saved profile to load. You're given the option of saving your settings in the final screen of the wizard. The second screen offers a simple choice between a Form Based Application and a Form Based Application with Data. Of course the Data option will let you bind your application to a data source. We'll select Form Based Application.
You can see the third screen in Figure 4. It gives you the option of adding specific controls and features to your initial application. In the beta version of the program that I reviewed, the Tool Bar and Status Bar options weren't yet implemented. I simply selected the menu option before going to the next screen.
Figure 4: The third screen of the VJ6 Application Wizard.
The fourth screen (see Figure 5) has options familiar to Visual Studio users; they allow you to select the types of comments automatically inserted by the wizard. Unless you plan to document your code using JavaDoc comments, you can usually uncheck this option. Keep in mind that TODO comments will show up in the VJ6 Task List. Sample Functionality comments are added for any sample code that's added by the Wizard.
Figure 5: The fourth screen of the Application Wizard lets you select the type of comments automatically inserted by VJ6.
The most useful feature of this Wizard is that it lets you choose the packaging options for your Java program (see Figure 6). Options here include standard Class files, a Windows EXE file, and Microsoft's compressed Cabinet (CAB) file format.
Figure 6: Selecting the packaging options for your Java program in the VJ6 Application Wizard.
The final page of the Application Wizard gives you the option of saving the selections you made as a profile for later use. It also gives you the option of viewing and saving a report of the options you selected.
Running the Application. When you've finished with the Application Wizard, you can test the generated code by pressing 5, or by clicking the Run button on the toolbar. This puts VJ6 into Run view which lets you see any Watch variables or messages in the Immediate window. Closing the application, or clicking on the Stop button, will return you to Default Design view.
Adding controls and code to your new project is easy. You just click on the WFC control you want to use (again, see Figure 1). Then either draw it onto your form in the size you want, or click on the form to create the control at the default size. The Properties window gives you access to the properties of the selected control.
Clicking on the lightning bolt icon in the Properties window gives you access to the events associated with a control. To hook a method to the event, you can select it from the drop-down list next to the event, or you can double-click the event to create a new method.
Data Form Wizard. The Data Form Wizard is similar to the Application Wizard. It walks you through the creation of a data-bound form using ODBC or an Access database. The wizard lets you select the tables or queries you want to display, then sets up a form containing the WFC DataNavigator control along with the fields you select.
The Data Form Wizard is available from the Add Item dialog box. You can access this dialog box by selecting Project | Add Item. I ran the Data Form Wizard using the Northwind database that ships with Microsoft Access as the data source. You can see the resulting form in Figure 7.
Figure 7: A form created using only the VJ6 Data Form Wizard. This one uses the Northwind database that ships with Microsoft Access as its data source.
The Builders
The Class Builder and the J/Direct Call Builder are both selected from the View | Other Windows menu. The Class Builder window is opened in the same dock as the Properties window by default. You'll need to undock the Class Builder window (see Figure 8) to see all the available tabs. To use the Class Builder, create a new class in your project and open the Class Builder window. You can also create a class directly by clicking the Add Class button. Make sure the code view of your class is open and has focus, then change the options in the Class Builder. You'll see the code in the class change in real time as you select and deselect options.
Figure 8: The Class Builder makes it easy to create custom classes.
The J/Direct Call Builder (see Figure 9) is designed to make it easy for you to access the Win32 API. You must specify the target class for the copied item; then you just select the Method, Struct, or Constant you want to access. Finally, simply click the Copy To Target button to copy the code to the target file.
Figure 9: The J/Direct Call Builder makes it easy to access the Win32 API.
IntelliSense
The Microsoft IntelliSense technology provides several important benefits while working with code in VJ6. On-the-fly, color syntax highlighting is an obvious one. For example, syntax errors are marked with a jagged red underline, just like a spelling error in Microsoft Word. These errors are also automatically added to the Task List to make them easy to locate and correct before running the program.
Another benefit of IntelliSense is Statement Completion. Suppose you're changing the property of a WFC control. Typing the name of the control, followed by a period, immediately brings up a small list box containing the next possible portion of code. After typing its first few letters, the method or property you're looking for will be highlighted. Then you can press T to automatically include the selected method or property. The process continues as needed for a particular statement. This feature is useful for experienced programmers, but it will surely make learning Java easier to learn.
Two other IntelliSense features of import are QuickInfo and DataTips. QuickInfo displays a floating window describing the parameters required for a given method, while the DataTips feature displays the value of a variable or expression in the code editor just by hovering over the variable with the mouse pointer.
Conclusion
We've just scratched the surface of what's available in VJ6. If you're looking for a tool to create Java solutions for Windows, this is the tool to use. The WFC, the packaging options, and the ability to easily incorporate Win32 API calls in your code make Visual J++ 6.0 a RAD development tool to be reckoned with.
Brian Johnson is a freelance writer in Orlando, FL. His most recent book is Microsoft Image Composer for Dummies [IDG Books Worldwide, 1998]. You can reach him at brianjay@gate.net or visit his home page at http://www.gate.net/~brianjay.