|
Samples Overview |
|
|
|
 Welcome! |
|
Introduction
\Awt
, \Debugger
, \DirectX
, \Jexegen
, \Jview
, \Native
, \Native_com
, \Native_raw
, \ScriptDebugger
, \Scripting
, \Version
The Microsoft SDK for Java provides several sample applications to help you get started with the classes and tools provided in this SDK. The directories covered in the following sections are in the \Samples directory in the SDK for Java. These directories contain the source code for the samples you will see in this article.
Contains samples demonstrating the Microsoft classes provided in the ms.com.awt package.
- \FontTest
- \Implemented as both an application and an applet to demonstrate the ms.com.awt classes FontX and FontMetricsX, in addition to other classes shipped with the SDK for Java. When run, FontTest uses the com.ms.lang.SystemX classes to determine the keyboard language. The sample allows the user to select a font and uses the FontX class to set the font text. It also demonstrates, using the FontMetricsX class, retrieving various font metrics selected by the user from a drop-down list. Text that the user types is displayed in a canvas text area.
- \Menux
- Demonstrates the use of the MenuX, MenuItemX, and MenuBarX classes in ms.com.awt. This sample can be run as an applet by directing your Java-aware browser to the menux.html file, or invoked as an application using the Jview tool. All source and class files are provided and a makefile for use with the Nmake tool (not provided in this SDK for Java).
- \RegKey
- Demonstrates and exercises the methods of the Microsoft RegKey class in the Microsoft AWT class. This sample can be run as a Java applet, using jview, or as a Microsoft Win32 application from RegKeySample.exe (created by the jexegen tool). For more information, see the ReadMe.txt file in the \RegKey directory.
Contains C++ and Java sample applications demonstrating the use of the Microsoft Debugger API for Java. For more information, see the ReadMe.txt file in the \Samples\Debugger directory.
- \C++ Debugger
- Contains source files for the Win32 C++ debugger sample console application,
JDebug.exe.
- \Hello
- Contains a sample "Hello World" Java application for debugging.
- \Java Debugger
- Contains the sample Java debugger and the source and class files for the Microsoft Debugger API for Java.
- \Java Debugger\com\ms\debug
- Class files for the Microsoft Debugger API for Java.
- \Java Debugger\Java
- Source files for the Microsoft Debugger API for Java.
Demonstrates the use of the Microsoft DirectX classes provided with this SDK for Java. All of these samples require that you have the DirectX2 run-time components installed on your computer. See the release notes on http://www.microsoft.com/java/sdk to download the DirectX2 run-time components.
- \d3drm
- Contains two sample directories with sample applications demonstrating the d3d class, which creates and manipulates Direct3D objects. Although samples in each of these directories can both be loaded as applets in the HTML pages that are provided, they cannot invoke the d3d classes due to security restrictions. Instead, run them as applications.
- \d3drm\flipcube
- Displays a window with a rotating cube. You can change various Direct3D parameters using menu commands. To run this, type "JView TestGraph" in this directory from an MS-DOS box.
- \d3drm\viewer
- Displays a viewer application window, from which you can open a window showing a rotating image. You can change various Direct3D parameters using menu commands. To run this, type "JView TestGraph" in this directory from an MS-DOS box.
- \dDraw\ddex3
- Demonstrates flipping between primary and secondary DirectDraw surfaces from within a Java application. To run this, type "JView TestGraph" in this directory from an MS-DOS box.
- \dSound\dSoundTest
- Demonstrates using the Microsoft DirectSound features from within a Java application. To run, type "JView dSoundTest" in this directory from an MS-DOS box or point your Java-enabled browser to the dSoundTest.html file in this directory. To view the text output, which describes the features being tested, run the application rather than the applet.
Provides sample class files to let you try out the Java Win32 Executable Generator (jexegen) tool.
For more information, see the readme.txt file.
- \Hello
- Provides a simple Hello class in Hello.java, which prints "Hello World." It also provides a batch file, called makeit.bat, which demonstrates the correct jexegen syntax to generate a Win32 executable version of this program. This sample demonstrates the proper usage of jexegen with classes and packages. The actual Hello.class file is in the \Test subdirectory, indicating that it is within the package named Test.
- \Mapplet
- Provides a set of classes for creating a Mandelbrot fractal image in a separate frame window. It also includes the makeit.bat batch file with the correct syntax for generating the Win32 executable from these classes.
- \Stub
- Provides a sample stub that can be used with the /BINDTO option of jexegen to access the class resource data from an application.
Includes the C++ source code for the Jview tool shipped with this SDK for Java. The Jview tool parses the command line, and then instantiates the Microsoft Win32 VM for Java (Microsoft VM for Java). The Jview tool then verifies the class and calls the Microsoft VM's COM (Component Ojbect Model) IJavaExecute2::Execute method to run the class.
The Microsoft VM uses the location of the jview.exe file to determine the path for the class library files. For this reason, to make the compiled version of jview work, you must do one of the following:
- Compile it into the SDK-Java\Bin directory, and then run it from that directory.
- Compile it in place, but supply a cp:a argument to the library path when you run it (that is, to either the Windows\System\Java\Lib or the SDK-Java\Lib directory).
Includes two sample applets to compare a standard Java applet against a similar applet that calls a native C function in a DLL for its computations.
- \SieveDemo
- Demonstrates using straight Java code to generate a prime number sieve, which calculates the number of prime numbers between 0 and a given array length. To run this applet, first compile the SieveDemo.java file using jvc, and then point your browser to the SieveDemo.html file.
- \SieveDemo2
- Demonstrates using a call to a native C function to generate a Sieve test. To run this applet, you must first build SieveDemo.dll from the SieveDemo.c, Sieve.h, and Sieve.def files. You must also build SieveDemo.class and Sieve.class by running Jvc on the SieveDemo.java file. Be sure to add the SDK for Java \Include directory to your compiler's include path and copy the SieveDemo.dll library to somewhere on your path. Then, point your browser to the SieveDemo.html file to run the applet.
Demonstrates communications between Java and COM. A native COM interface, INatCom, is implemented in C++ in the \com directory. It has two simple math methods in it, MultParm() and Square(). It also has a third method, GetClass(), which returns the IJNatCom interface. IJNatCom is implemented in Java. This method is then called from a Java application.
In addition to the tools in the SDK-Java\Bin directory, the \native_com sample requires the following Win32 tools:
- nmake.exe
- mktyplib.exe
- cl.exe
- link.exe
- mapsym.exe
- regsvr32.exe
Use the following steps to build and run this sample.
- From \native_com, type "nmake /a".
- Register the INatCom object in natcom.dll. Change to the \com directory. Type
regsvr32 natcom.dll
- Register the JINatCom object implemented by Java by changing to the \java\_2 directory and typing "reg" to run the reg.bat batch file.
- Run the sample by changing to the \java\_1 directory and typing:
JVIEW java._1.JMain.
Note that this assumes that your CLASSPATH environment variable includes the current directory.
- \Com
- Provides the natcom.cpp and natcom.h files required to implement the INatCOM COM interface. This is a self-registering object, so you can just run regsvr32 on the DLL to register it. Note that the implementation for the GetClass method calls QueryInterface to retrieve the JINatCom interface pointer and, if successful, then calls the JINatCom.ccwHelloWorld method to demonstrate calling the JINatCom COM object from the NatCom COM object.
- \Java
- Contains two directories, \_1 and \_2. The \_1 directory contains the jmain class executed from jview. \_2 contains the Java implementation of a COM class.
\_1 Provides a makefile that creates type library (TLB) files, natcom.tlb and jnatcom.tlb, from the object definition library files in ..\..\odl (using the Win32 mktyplib.exe tool). It then creates Java classes, natcom.java and jnatcom.java, from the TLB files using the JavaTLB tool. The makefile then uses the jvc compiler to compile these Java classes, together with the JMain.java file, into JMain.class.
The jmain.class contains the main() method required for running this as an application. This main() method creates a JMain class and calls JMain.ExerciseJCW to access the methods in the COM classes.
The Jmain.class constructor instantiates an INatCom object from the natcom.class library (using the Java new operator). The JMain.ExerciseJCW method does two things. First, it calls and uses the math methods in INatCom, which are implemented in C++. (Since the C++-written COM class is wrapped by this Java class, it is called a "JCW" or Java-callable wrapper.) Next, ExerciseJCW() instantiates a jINatCom object, which is implemented in Java and wrapped as a COM object. Instead of calling the Java new operator to instantiate this COM class from Java (which it could have also done), this method calls the third jNatCom method, GetClass, to demonstrate how to instantiate one COM object from another COM object. It gets the pointer back to that object, and then calls its one method (HelloWorld()) from the Java class.
\_2 Provides the Java implementation for the jINatCom COM object. This object is defined by the jnatcom.odl file in ..\..\odl. This implementation represents a COM-Callable Wrapper (CCW), meaning it is Java implementation of a standard COM object (that is, callable by other COM objects). It has only two methods. The first is ccwHelloWorld. It is meant to be called from another COM object (and is called by the C++ NatCom implementation of GetClass). The second is HelloWorld. It is called from the Java JMain.ExerciseJCW() method in ..\_1.
- \Odl
- Provides the Object Definition Language (ODL) files, natcom.odl and jnatcom.odl. Natcom.odl specifies the type library definition for an OA object that is implemented in C++. Jnatcom.odl specifies the type library definition for an ActiveX Automation object that is implemented in Java. These are both built into type libraries (natcom.tlb and jnatcom.tlb) by the makefile in the .\Java directory.
This sample demonstrates use of the native interface of the Microsoft VM for Java. The native methods are implemented in a dynamically-linked library (DLL). The sample accesses various Java methods and variables from native code. It also demonstrates garbage-collectionsafe operations in native code.
The JMain constructor loads the DLL, and then proceeds to call various methods to demonstrate Java and native code interaction.
To build this sample, invoke the makefile in native_raw directory by changing to that directory and typing:
nmake /a
To run this sample, change to the binaries directory and run jview:
jview Jmain
- \binaries
- Contains the Java class files and the natlib.dll file containing the native methods.
- \java
- Contains source code for Java classes.
- \native
- Contains source code for native library.
This directory provides an HTML page containing sample JavaScript and Java code for demonstrating cross-language debugging using the Microsoft Java Script Debugger. The JavaToJScript.html file contains JavaScript code that calls into the JavaTest class, which is provided in the CAB file, JavaTest.cab. The JavaTest.java file provides the source code for this class.
To test the debugger with this sample code, you must first install the Microsoft Script Debugger and enable ActiveX debugging. Follow these steps to run the Microsoft Script Debugger on this sample:
- Install the script debugger by running the self-extracting executable from the ScriptDebugger subdirectory of the directory in which you installed the SDK for Java. This creates a SetDebug.exe program in your \Windows directory.
- Run "setdebug -e" to enable Java ActiveX debugging.
- Run "setdebug -p <ScriptDebugger Directory>", to add the directory containing JavaTest.java to the Java source path (where <ScriptDebugger Directory> is the full path to this directory as installed on your machine).
- Conduct the sample debugging session. To get started, load the JavaToJScript.html page and select the Break at Next Statement from the Edit menu in Internet Explorer. The ScriptDebugger has its own online Help. For more information, see the Tools section in the Microsoft SDK for Java documentation.
- Run "setdebug -d" to disable Java ActiveX debugging.
This sample includes an HTML page that demonstrates the use of Microsoft Visual Basic Scripting Edition (VBScript) to control a Java applet.
This directory provides support for adding versioning to your classes and packages. Versioning support allows the version of your classes or packages to be determined after being installed on a user's system. Two classes shipped with the Com.ms.util package, SystemVersionManager and FileVersionInformation, in the SDK for Java provide base support in the Microsoft VM for Java. Your classes should include a VersionManager class, which is provided in this directory, to ensure that version management works on virtual machines that do not include the SystemVersionManager class. Your distributed packages should include a Version class, included in TestPackage subdirectories, to enable checking for the package version.
Run the complete set of version tests by pointing your browser to index.html. This file uses four other HTML files:
- Tests.html provides the left panel, which calls Sysinfo.html, Pkginfo.html, and Fileinfo.html.
- Sysinfo.html provides the SystemVersionInformation panel and calls the SystemVersionTest applet to provide current version information on your system.
- Pkginfo.html queries and displays the version information in two test packages from the \TestPackage subdirectory.
- Fileinfo.html designed to display file version information in a separate window; however, since file information cannot be read from the browser for security reasons, only the security exceptions are displayed when this is run from the browser. To run this application, type Jview VersionPanelTest. This opens the file dialog box, so you can pick a file to display its version information. For an example, try the \Bin directory of the SDK for Java and open at any of the executable files there.
- \TestPackage
- Contains a Version class with the version string "Test Package 1.0."; used by the the VersionTest application to determine the package version.
- \TestPackage\TestPackage
- Contains a Version class with the version string "Subpackage Version 1.0." It is also used by the VersionTest application.