home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Sams Teach Yourself Visual J++ 6 in 21 Days
(Publisher: Macmillan Computer Publishing)
Author(s): Rick Leinecker
ISBN: 0672313510
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Using Other Controls

There are other controls that you can use in your Visual J++ programs. Many ActiveX controls either come with Visual J++ and aren’t in the ActiveX control list, or they come with other packages and can be used by Visual J++.

To find other ActiveX controls that you can use in Visual J++ programs, select Customize Toolbox from the Tools menu. Click on the ActiveX Controls tab and a large list of available controls will appear. To add these to the Toolbox Window under the ActiveX tab, click on them.

Let’s add a new control then use it in a program. Create a new Visual J++ application named UseActiveX3. Select Customize Toolbox from the Tools menu. Click on the ActiveX Controls tab. Check the Microsoft Web Browser control as shown in Figure 20.6.


Figure 20.6  Add the Microsoft Web Browser to the list of ActiveX controls.

Now, select the ActiveX Controls tab in the Toolbox Window. Click on the Microsoft Web Browser control (labeled Explorer in the ActiveX tools) and place it on the Form window so that it occupies most of the Form window as shown in Figure 20.7.


Figure 20.7  The Microsoft Web Browser control should take up most of the Form window.


Note:  The process of adding the control to your form for the first time might take as much as a minute. Be patient.

Now all you need to do to get the control working is make a call to the Navigate() method. (Listing 20.1 shows the source code for the UseActiveX3 program.) This method takes five arguments.

The first is a string designating the URL to which you’ll navigate. The second is a value indicating any flags you want to use; this will always be zero for your use. The third argument is the name of the frame in which you’ll display this control; we’ll use a null value. The fourth argument is a value that specifies the HTTP headers to send to the server; we’ll use a null value. The fifth argument is the data to send for an HTTP POST; we’ll use a null value.

In almost every case, when you use the Navigate() method, the only argument that won’t be zero or null will be the first argument.


Caution:  The data that you pass to arguments two through five must be a variant.

The following example shows how we created Variant classes with the value of zero and passed them to the Navigate() method:

webBrowser1.Navigate( "http://www.infinitevision.net",
    new Variant( 0), new Variant( 0), new Variant( 0), new Variant( 0));

The source code for the UseActiveX3 program will be helpful for you. It’s shown in Listing 20.1.

Listing 20.1 This is the Source Code for the UseActiveX3 Program

1   import com.ms.wfc.app.*;
2   import com.ms.wfc.core.*;
3   import com.ms.wfc.ui.*;
4   import com.ms.wfc.html.*;
5   import com.ms.com.*;
6
7   /**
8    * This class can take a variable number of parameters on the command
9    * line. Program execution begins with the main() method. The class
10   * constructor is not invoked unless an object of type 'Form1' is
11   * created in the main() method.
12   */
13  public class Form1 extends Form
14  {
15       public Form1()
16      {
17          // Required for Visual J++ Form Designer support
18          initForm();
19
20          webBrowser1.Navigate( "http://www.infinitevision.net",
21              new Variant( 0 ), new Variant( 0 ), new Variant
                ⇒( 0 ), new Variant( 0 ) );
22
23      }
24
25      /**
26       * Form1 overrides dispose so it can clean up the
27       * component list.
28       */
29      public void dispose()
30      {
31          super.dispose();
32          components.dispose();
33      }
34
35      /**
36       * NOTE: The following code is required by the Visual J++ form
37       * designer.  It can be modified using the form editor.  Do not
38      * modify it using the code editor.
39       */
40      Container components = new Container();
41      shdocvw.WebBrowser.WebBrowser webBrowser1 = new
        ⇒shdocvw.WebBrowser.WebBrowser();
42
43      private void initForm()
44      {
45          // NOTE:  This form is storing resource information in an
46          // external file.  Do not modify the string parameter to any
47          // resources.getObject() function call.  For example, do not
48          // modify "foo1_location" in the following line of code
49          // even if the name of the Foo object changes:
50          //     foo1.setLocation((Point)resources.getObject
            ⇒("foo1_location"));
51
52          IResourceManager resources = new ResourceManager
            ⇒(this, "Form1");
53          this.setText("Form1");
54          this.setAutoScaleBaseSize(13);
55          this.setClientSize(new Point(691, 397));
56
57          components.add(webBrowser1, "webBrowser1");
58          webBrowser1.setLocation(new Point(8, 8));
59          webBrowser1.setSize(new Point(672, 376));
60          webBrowser1.setTabIndex(0);
61          webBrowser1.setOcxState((AxHost.State)resources.getObject
            ⇒("webBrowser1_ocxState"));
62
63          this.setNewControls(new Control[] {
64                              webBrowser1});
65
66          webBrowser1.begin();
67      }
68
69      /**
70       * The main entry point for the application.
71       *
72       * @param args Array of parameters passed to the application
73       * via the command line.
74       */
75      public static void main(String args[])
76      {
77          Application.run(new Form1());
78      }
79  }

When the program runs, you’ll see it go to the Infinite Vision site at www.infinitevision.net as shown in Figure 20.8.


Figure 20.8  This program uses Microsoft’s Web Browser control to navigate on the Internet.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.