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.
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.
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.
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:
Preparing to create a new resource.
Design your menu from the menu-creation window.
This is an example of a menu you can create.
Visual J++ converts your resource file to Java source code.
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.
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.
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:
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.
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 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.