In this chapter, you will learn what ActiveX and COM technology is all about. Actually, ActiveX and COM require no new programming statements or advanced technical fortitude. You will see that you can use an ActiveX control, such as a Visual Basic OCX control, that you purchased for Visual Basic applications, inside your Visual J++ applets. To the Java language, an ActiveX control looks and acts just like other objects inside the applet.
The ActiveX and COM technologies let you harness pre-written routines and controls inside your own applets. You'll not really write programs as much as you'll piece together ActiveX controls that do what you want them to do.
According to Microsoft, the ActiveX technology is the most exciting thing to hit the world since sliced bread. Generally, Microsoft feels this way about all its products! Of course, one has to admit that Microsoft does seem to produce some of the best software in the world (just look at Visual J++!) so Microsoft's excitement seems warranted in many instances.
The ActiveX technology produces controls, such as command buttons and scroll bars (and even much more exciting controls), both on the Web as well as the desktop. In other words, instead of using controls such as the common Visual Basic VBX, OCX, and OLE controls for desktop applications but then using AWT components for Web applications, software developers can create ActiveX controls that work everywhere. Visual J++ lets you create ActiveX controls using Visual J++'s Java language implementation.
The Common Object Model (COM) technology includes all OLE (Object Linking and Embedding), OLE's internal automation technology, as well as new standards for sharing objects between programs. OLE has been around since 1990, and therefore, you can use all existing OLE tools from inside your Visual J++ program because of Visual J++'s support for COM includes, by default, OLE support as well.
ActiveX controls go way beyond controls that mimic (and improve upon) AWT components. ActiveX controls manipulate and control sound, video, hardware, and even virtual reality technology. As hardware vendors develop new hardware technology, such as new storage and video devices, you'll have easy I/O access to that new technology through your programs simply by using hardware vendor-supplied ActiveX controls.
Perhaps the biggest advantage of ActiveX controls is that multiple ActiveX controls on a Web page can communicate with each other and pass data back and forth. This two-way communication between controls virtually eliminates tedious programming methods that you would otherwise have to write. By utilizing the COM technology, these ActiveX controls communicate using a standard I/O model.
Visual J++ makes the COM object (in this case, the ActiveX control although there exist many other kinds of COM objects) look to your Visual J++ applet like a pre-defined class. A COM object has properties, such as a maximum and minimum value if the control requires limited values, and your Visual J++ program will access those values as if the values were class data members. In reality, however, you know that the values came to you through the COM object's COM-defined interfaces (called typelibs meaning COM's type libraries).
Lots of non-Microsoft companies (even their competitors!) support or plan to support ActiveX technology. Borland, Oracle, Sun, Sybase, and Symantec have all agreed to offer partial or full ActiveX support in their products. Obviously, the industry takes ActiveX as seriously as Microsoft does. Perhaps the reason for their interest is that an ActiveX control works seamlessly in Visual C++, Visual Basic, and even Borland's Delphi and Borland C++ technologies with no modifications. In addition to software vendor support, ActiveX also works on multiple platforms including Macintoshes and UNIX-based computers.
Just because you use Visual J++ and program in the Java language does not limit you to ActiveX controls written in Java. No matter which language the developer used to create an ActiveX control, you'll be able to utilize that control inside your Visual J++ applet.
ActiveX Plug-Ins
Before you or your end-users can utilize ActiveX controls, you must have an ActiveX-enabled Web browser. Microsoft's Internet Explorer 3.0 supports ActiveX controls, so if you or an end-user uses Internet Explorer 3.0, you'll have no problems. Netscape's Navigator pre-3.0 release versions do not support ActiveX controls, but Netscape has provided an ActiveX plug-in utility.
Figure 17.1 shows how your ActiveX control integrates into the Visual J++-Java-Web browsing environment.
Visual J++ creates your Web site's Java-based applet and combines ActiveX controls with the applet.
If you point your ActiveX-enabled Web browser to the following URL, you'll be able to view a rich collection of Microsoft-supplied ActiveX controls:
http://www.microsoft.com/activex/gallery/
Figure 17.2 shows the site's opening page. The lefthand window lists each ActiveX control by category. Scroll through the list to find a control you're interested in. Not only can you read about the controls, but you can even download the control and use the ActiveX control inside your own applet.
You can download and try numerous ActiveX controls from Microsoft's ActiveX Web site.
Spend some time at this ActiveX site and study the ActiveX examples that you can view and download. Figure 17.3 gives you a better idea of what you can expect when you click a control's name. Figure 17.3 shows the information screen for the Stock Ticker ActiveX control (located under the Real Time Data Acquisition category at the left of the Web site). The screen describes the control that you can embed in your own applets to display data from an URL that continuously updates at a pre-selected time interval. When you click this control's Control Information Page hypertext link, Internet Explorer (or your ActiveX-enabled browser such as Netscape Navigator 3.0) automatically downloads the control to your computer and executes the control on the control's Web page as if Microsoft had sent the control straight to you as an embedded applet.
Click an ActiveX control to see what the control does.
Where does the Stock Ticker ActiveX control get its information? In other words, how does the Stock Ticker ActiveX control know which URL to display? You have to tell the Stock Ticker ActiveX control which URL to show if you use the control inside your own applet. Before you can fully use a control, you must download the control's type library from the vendor to your own system.
When you obtain an ActiveX control that you want to use in your applet, you will get documentation that describes the control's interface. Just as a class contains an interface that defines data members and methods (see chapter 19, "Visual J++ Applet and AWT Class Refernece," for examples of some pre-defined class interfaces), the ActiveX control also contains data members and methods you can access within your applet to make the control behave the way you want it to behave.
There is actually nothing special you need to do other than install the ActiveX control according to the ActiveX control's installation instructions, insert the appropriate import command inside all your Visual J++ code that will use the ActiveX control's type library (which is nothing more than an ActiveX control's class definition that conforms to the pre-defined industry-standard COM specification), and then use the ActiveX control as if it were an object.
For example, suppose you want to place a pop-up menu on your applet's window. Instead of using the AWT features, you obtain an ActiveX menu control that sports the following features:
Let's call the ActiveX menu control FancyMenu. The FancyMenu's documentation lists all the pre-defined named constants and methods you can use to display and manipulate the menu as well as how your applet will get the user's selected menu choice. After you install the FancyMenu control, you'll import the control's type library into your Visual J++ program by using the following line at the top of your class' code:
import FancyMenu.ActiveX.control; // Imports the COM object
You then instantiate a menu object just as you do any other object. According to FancyMenu's documentation, you might use the FancyMenu class (remember that a COM object looks just like a class to the Java language) to instantiate a menu object with the following line of code:
FancyMenu userMenu = new FancyMenu; // Instantiate the menu
Perhaps you must tell the ActiveX control how many menu choices your applet requires as well as specify the text for each choice. Although we're describing an imaginary ActiveX control, the following code is similar to what you might write for such a control:
userMenu.setChoices = 5; // Request a total of five choices
userMenu.SetChoiceText(1) = "Add items"; // 1st option
userMenu.SetChoiceText(2) = "Change items"; // 2nd option
userMenu.SetChoiceText(3) = "Delete items"; // 3rd option
userMenu.SetChoiceText(4) = "Print items"; // 4th option
userMenu.SetChoiceText(5) = "Close menu"; // 5th option
Perhaps a FancyMenu pre-defined variable holds the user's chosen selection. You might test the menu control's selection with a switch statement such as the following:
switch (userMenu.choice)
{
case 1: { addItem(); // Calls my addItem() method
break; }
case 2: { chaItem(); // Calls my chaItem() method
break; }
case 3: { delItem(); // Calls my delItem() method
break; }
case 4: { priItem(); // Calls my priItem() method
break; }
case 5:
default: { userMenu.hide = true; // Get rid of the menu
break; }
}
What's new about ActiveX programming? Nothing. That's the idea. Once you install an ActiveX control, your Visual J++ program will work with the control, controlling the control in effect, just as your code manipulates and manages objects that you define inside your class.
The goal of this chapter was to teach you about the ActiveX and COM technologies. As you saw, ActiveX brings a lot of new technology to your programs but does not bring a big programming burden to you. Programming ActiveX controls is just as easy as programming your own class's objects.
As long as your Web browser is ActiveX-aware, as is Internet Explorer 3.0, you will be able to view Web pages that contain such applets. Of course, your end-users must also have an ActiveX-aware Web browser but the ActiveX/COM technology is gaining ground so rapidly and so many companies are supporting the standard, that most Web browsers should be ActiveX-aware soon if they are not already.
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.