- Using Visual J++ -

Chapter 18

Your Visual J++ Future


This chapter was originally titled "Compatibility Issues," but we couldn't find any! Visual J++ supports the entire Java specification including all the industry de facto standard pre-defined classes. If Visual J++ is not fully compatible it's because Visual J++ goes a step further than the typical Java implementation and improves upon the standard and adds extended features not found elsewhere.

This chapter explains some of Visual J++'s extensions. Now that you can understand the need for the more advanced Visual J++ features, you will see how Visual J++ works with you to help you build better applets faster. This chapter presents a list of features that you'll want to take advantage of as soon as you begin developing more powerful applets. Describing these future enhancements helps us learn more about Visual J++'s strengths and weaknesses.

Compiling Just in Time

With Internet Explorer 3.0, Microsoft introduced Just-In-Time compilation (JIT) for Java applets. While most other Web browsers do not yet support JIT, many may be adding JIT in future releases. The Java JIT makes your Java applets run much faster than they would run without the JIT technology.

To understand JIT, recall what Visual J++ produces from your project's builds: executable content in the form of bytecode. Bytecode is machine-independent, which means that any Java-enabled Web browser can execute Java bytecode. The way that a Web browser accomplishes this feat is to translate, on the fly during the applet's execution, each bytecode instruction into the machine's native machine language.

This pseudo-program translation slows down a Java program much more than if Visual J++ first compiled the Java program into machine language. Visual J++ does not compile into machine language, however, because which machine would be the target machine? PCs? Macs? UNIX-based minicomputers? As you might be able to tell, the best Visual J++ can do is translate your Java code into the universal bytecode that all computers with Java-enabled Web browsers can read, interpret, and convert into machine codes.

The reason that Web browsers execute Java applets more slowly than pre-compiled programs is this code-by-code translation. If your applet calls the paint() method 14 times during its execution, the Java-enabled Web browser must convert the paint() method's bytecodes into the host machine's machine language each of those 14 times.

The concept of JIT is simple, and you might already be guessing what takes place. The JIT Web browser, such as Microsoft's Internet Explorer 3.0, keeps track of all methods it translates and stores the translated machine language in a table. If the applet subsequently calls that translated method, the browser does not have to re-interpret the bytecode; instead, the Web browser executes the pre-stored machine language from its growing table of code.

 
JIT compilers do not improve the speed of simple, purely sequential programs, and in a handful of instances, a JIT compiler can actually slow down an applet's execution. Nevertheless, in the vast majority of cases, JIT improves the applet's execution speed dramatically.

Creating and Editing Resources

Visual J++ makes it easy for you to create and edit the following resources:

You've seen many of these resources mentioned in this book, especially the AWT-related resources. Visual J++ certainly supports AWT resources, but Visual J++ goes even further. The Visual J++ resources are Windows-like resources used throughout Windows applications. By using the Visual J++'s resource creation tools, you can create resources such as menus and dialog boxes, and then work with those resources in Java code. Without the Java Resource Wizard, you would have to build menus and dialog boxes using tedious (but simple) AWT class methods.

A problem does arise, however, in that Visual J++ seems to promise more than it can deliver. For example, Windows programmers have worked with string tables and version controls for years, but even though you can create those resources from within Visual J++, Visual J++ cannot really use those resources. In fact, Visual J++ only supports the resources that the AWT classes support, namely dialog boxes and menus.

Visual J++ does not even support bitmaps the same way that other Windows development tools do. Visual J++'s Java-based language works only with .Gif file images as described in chapter 15, "Displaying Graphic Images." Therefore, you must be able to convert bitmaps with the .Bmp file-name extension to the .Gif extension if you want to use Visual J++'s bitmap editor-created bitmaps in your applets. The resources that Visual J++ truly support, therefore, despite the Insert Resource dialog box, are menus and dialog boxes; additionally, Visual J++ lets you create bitmap images that you can use only if you have the means to convert those bitmaps to .Gif files.

 
Despite the (temporary, we hope) broken promise of full-resource support, you've got to admit that using a full-screen editor to build dialog boxes and menus is much simpler than using AWT method descriptions to build the dialog boxes and menus. For example, you can see the dialog boxes as you create them instead of having to run the applet before seeing the dialog box.
 
 
Visual J++ does not support resources the same way as Visual C++ does. Visual J++ supports only resources that AWT recognizes and those resources keep AWT's look and feel as opposed to the smoother Windows versions. See the "A Microsoft Wish List" section at the end of this chapter to see what Microsoft has in the works for more advanced resources.

Suppose that you want to add a menu to an applet but you'd rather create the menu using full-screen editing tools (the Resource Editor) instead of piecing together AWT methods. To create the menu, perform the following steps:

  1. Choose Insert, Resource. The Insert Resource dialog box appears (see figure 18.1).


FIG. 18.1

Preparing to create a new resource.

  1. Click Menu in the Resource Type list box.
  2. Click the OK button. Visual J++ opens the Developer Studio's menu-creation window (see figure 18.2). The menu creation window is an extremely simple full-screen menu specification screen.


FIG. 18.2

Design your menu from the menu-creation window.

  1. Place your menu's primary menu bar items across the top of the menu bar. For example, click the empty space in the upper-left corner of the gray bar to display the first menu bar item's location. Type &File (the ampersand indicates where you want a menu hot key, such as Alt+F; Visual J++ underlines that character when the menu appears) and press Enter to add the first menu bar item. As you type, Visual J++ opens the item's Properties dialog box where you can select from a list of menu item options.
  2. Click right arrow and type &Edit to add the next item. Press Enter, click the right arrow, and then type &Help for the final item.
  3. To add the submenu items, click a menu option such as File and press the down arrow. Visual J++ lets you add the File pull-down menu items. Add two or three items, and then add some items to the other two menu bar options so that your screen looks something like figure 18.3.


FIG. 18.3

This is an example of a menu you can create.

  1. Once you finish creating the menu, close the menu-creation window. Visual J++ displays a resource tree showing your menu's hierarchical location and default name. The top name is the directory folder in which Visual J++ stores the menu and other resources. When you eventually choose File, Save or when you close your project workspace, Visual J++ prompts you for a resource file name. The file will have the .Rct file-name extension; you'll later use this file to connect the resource to your Visual J++ program. (This file is not directly usable by Visual J++ but Visual J++ can convert the file to a Visual J++ source code file as described next.) Keep track of the file's name and location.
  2. Close the resource window.
  3. Choose Tools, Java Resource Wizard. The Java Resource Wizard converts the menu's resource file to a Java-enabled AWT file that you can modify, add to, or cut and paste from.
  4. 10. Type the complete path and file name for the menu's resource file in the Java Resource Wizard's opening dialog box.
  5. 11. Click the Next button to display the second Java Resource Wizard dialog box (see figure 18.4). This dialog box displays the resources in the .Rct file, including the logical name for the menu, which you don't need for Visual J++ programming but which might be used in Visual J++'s future editions.


FIG. 18.4

Visual J++ converts your resource file to Java source code.

  1. 12. Click Finish to complete the wizard's task. Visual J++ converts the menu that you designed to Java code and lets you know when the process finishes and the name of the Java file that holds the menu description.

Listing 18.1 contains the Java code that Visual J++ produced from Figure 18.3's simple menu. Notice that the code uses the AWT class to produce a Java menu. The menu will not look like Windows menus but will take on the standard Internet applet look and feel.

 
Of course, you must fill in the menu code to respond to the user's selections using pre-defined AWT menu-handling method code described in chapter 19, "Visual J++ Applet and AWT Class Reference."


Listing 18.1 Visual J++ Generates Menu-Handling Code

//-----------------------------------------------------------------------
// IDR_MENU1.java:
// Implementation for menu creation class IDR_MENU1
//
//-----------------------------------------------------------------------
import java.awt.*;
public class IDR_MENU1
{
Frame m_Frame = null;
boolean m_fInitialized = false;
// MenuBar definitions
//------------------------------------------------------------------
MenuBar mb;
// Menu and Menu item definitions
//------------------------------------------------------------------
Menu m1; // &File
MenuItem ID_FILE_OPEN; // &Open
MenuItem ID_FILE_SAVE; // &Save
MenuItem ID_FILE_EXIT; // E&xit
Menu m5; // &Edit
MenuItem ID_EDIT_COPY; // &Copy
MenuItem ID_EDIT_CUT; // Cu&t
MenuItem ID_EDIT_PASTE; // &Paste
MenuItem m9; // Separator
MenuItem ID_EDIT_DELETE; // &Delete
Menu m11; // &Help
// Constructor
//------------------------------------------------------------------
public IDR_MENU1 (Frame frame)
{
m_Frame = frame;
}
// Initialization.
//------------------------------------------------------------------
public boolean CreateMenu()
{
// Can only init controls once
//-------------------------------------------------------------
if (m_fInitialized || m_Frame == null)
return false;
// Create menubar and attach to the frame
//-------------------------------------------------------------
mb = new MenuBar();
m_Frame.setMenuBar(mb);
// Create menu and menu items and assign to menubar
//-------------------------------------------------------------
m1 = new Menu("&File");
mb.add(m1);
ID_FILE_OPEN = new MenuItem("&Open");
m1.add(ID_FILE_OPEN);
ID_FILE_SAVE = new MenuItem("&Save");
m1.add(ID_FILE_SAVE);
ID_FILE_EXIT = new MenuItem("E&xit");
m1.add(ID_FILE_EXIT);
m5 = new Menu("&Edit");
mb.add(m5);
ID_EDIT_COPY = new MenuItem("&Copy");
m5.add(ID_EDIT_COPY);
ID_EDIT_CUT = new MenuItem("Cu&t");
m5.add(ID_EDIT_CUT);
ID_EDIT_PASTE = new MenuItem("&Paste");
m5.add(ID_EDIT_PASTE);
m9 = new MenuItem("-");
m5.add(m9);
ID_EDIT_DELETE = new MenuItem("&Delete");
m5.add(ID_EDIT_DELETE);
m11 = new Menu("&Help");
mb.add(m11);
m_fInitialized = true;
return true;
}
}

As with menus, you can create complex dialog boxes that Visual J++ converts to AWT containers that work as if you had built the containers using tedious methods.

 
If you include a resource in a dialog box that AWT does not support, such as a slider control, Visual J++ ignores that dialog box control when building the Java AWT-based code. Therefore, don't add items to your dialog boxes until Microsoft adds Java classes that support those special resources.
 
 
Isn't it easier to create menus and dialog boxes using arrow keys by placing items on your screen and labeling items properly than creating those same resources method-by-method call?

A Microsoft Wish List

What will Microsoft do in future versions of Visual J++? Even Microsoft does not know, but at the time of this writing, Microsoft is discussing the following features for future Visual J++ editions:

 
The computer industry is making a conscious push to blur the lines between a stand-alone PC, a networked PC, and a PC or networked PC connected to the Internet. The world-at-your-fingertips data model does conjure intriguing ideas.

All in all, the future of Visual J++ looks bright and Microsoft's language extensions seem promising. As with all of Microsoft's development tools, Microsoft will continue to evolve Visual J++ into a product that fills many people's programming needs.

Summary

The goal of this chapter was to introduce additional Visual J++ features and discuss future enhancements. You learned about the Just-In-Time compiler that Internet Explorer 3.0 supports which speeds your applet's execution. Although you don't have to know about the Just-In-Time compiler to use it, you will appreciate the applet speed that Internet Explorer 3.0 produces.

Visual J++'s resource support is minimal at this time, but you will be able to create any Windows resource with Visual J++. Future Visual J++ upgrades ought to be able to take advantage of all of these resources. For now, you will be able to paint your menu and dialog boxes instead of taking the tedious time needed to build these resources by calling AWT methods.

Here are the points this chapter covered:


Previous Page TOC Next Page

| Previous Chapter | Next Chapter |

| Table of Contents | Book Home Page |

| Que Home Page | Digital Bookshelf | Disclaimer |


To order books from QUE, call us at 800-716-0044 or 317-361-5400.

For comments or technical support for our books and software, select Talk to Us.

© 1996, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.