Java Programing

April 28, 2007

CHAPTER 18 Java 3D system architecture 18.1 Introduction

Filed under: Java 3D Programming — webmaster @ 1:25 am

18.2 Threads running a Java 3D application As you can see from tables 18.1 through 18.3, a typical Java 3D application contains many threads, some concerned with system behavior, some running the GUI event processing, and some (13) controlling the Java 3D runtime environment. The two ThreadGroups, main and Java 3D, are subgroups of the top-level system ThreadGroup. The Java 3D threads have the default thread priority of 5, although this can be controlled using the VirtualUniverse.setJ3DThreadPrioritymethod. The priority must fall between Thread.MAX_PRIORITYand Thread.MIN_PRIORITY. The default is Thread.NORM_PRIORITY. The priority of the parent ThreadGroup(Java 3D) cannot be exceeded. Note that unlike nondaemon threads, daemon threads do not have to exit their Runnable s runmethod for the JVM to exit. Table 18.1 Thread Group: System Name Priority Daemon Reference Handler 10 Yes Finalizer 8 Yes Signal Dispatcher 10 Yes Table 18.2 Thread Group: Main Name Priority Daemon Main 5 No AWT-EventQueue-0 6 No SunToolkit.PostEventQueue-0 5 No AWT-Windows 5 No Image Fetcher 1 8 No Image Fetcher 0 8 No Table 18.3 Thread Group: Java3D Name Priority Daemon J3D-MasterControl 5 No J3D-RenderingAttributesStructureUpdateThread 5 No J3D-TimerThread 5 No J3D-BehaviorStructureUpdateThread-1 5 No J3D-GeometryStructureUpdateThread-1 5 No J3D-SoundStructureUpdateThread-1 5 No J3D-RenderingEnvironmentStructureUpdateThread-1 5 No J3D-TransformStructureUpdateThread-1 5 No J3D-BehaviorScheduler-1 5 No J3D-RenderStructureUpdateThread-1 5 No J3D-SoundSchedulerUpdateThread-1 5 No 313

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

CHAPTER 18 Java 3D system architecture 18.1 Introduction

Filed under: Java 3D Programming — webmaster @ 1:25 am

CHAPTER 18 Java 3D system architecture 18.1 Introduction 18.2 Threads running a Java 3D application 18.3 MasterControl 18.4 BehaviorScheduler 18.5 InputDeviceScheduler 18.6 Renderer 18.7 StructureUpdateThread 18.8 TimerThread 18.9 SceneGraphObject 18.10 Node types 18.11 Exception Strings 18.12 J3D DLL 18.13 Summary By now I hope you are curious to know how Java 3D achieves what it does. In this chapter we gallop through some of the implementation details behind the Java 3D API gaining insight into getting the most from Java 3D and maximizing the performance of your applications. This chapter gives you some clues for implementing your own 3D graphics API in Java. Sun s Java 3D internal implementation details are all subject to change at any time. The version described here is Java 3D 1.2 running on the Win32 platform. 18.1 Introduction The implementation of the Java 3D API has undergone considerable revision between the 1.1 and 1.2 versions of the API. About 70 percent of the Java code was rewritten between these two versions! The Java 3D 1.1 architecture was fairly simplistic and could be considered a proof-of-concept implementation of the API. Version 1.2 moved to a message-based architecture and took tighter control of the various worker threads created by the API implementation. The collision detection thread was removed in 1.2, and collision detection is carried out by the new TimerThreadfunctionality. By explicitly activating the threads in the system, the 1.2 API has removed the free-running threads (behaviors and collision detection) that caused 100 percent CPU utilization in Java 3D 1.1. 312

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

April 27, 2007

Figure 17.6 After installation the Java 2 plug-in

Filed under: Java 3D Programming — webmaster @ 6:09 pm

JAR file extension options: http://java.sun.com/docs/books/tutorial/jar/index.html 17.2.5 Applets and security Security is a complex topic for applets. When SwingTestis running as an applet, it is subject to the Java sandbox principle. The applet can only read and write files from its own codebase (the URL that contains the applet). Indeed, some care must be taken while programming to ensure that applet-safe APIs are used to access files. In general, you will need to work exclusively with URL objects, as direct access using files does not always work, even when using the applet s codebase. When you run the SwingTestexample you will notice the following exceptions: Failed to save image: java.security.AccessControlException: access denied (java.io.FilePermission image.jpg write) java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM) The first exception occurs because the applet cannot write the captured image onto the local file system, while the second exception occurs because applets cannot call System.exitto exit the JVM, but are rather under the control of the Java 2 plug-in. Access permissions can be configured using the Java 2 security policy descriptors. A full discussion of Java 2 security is beyond the scope of this book. For more details refer to http://java.sun.com/j2se/1.3/docs/guide/security/ 17.3 Conclusions Installation of Java 2 client-side applications, particularly those requiring other extensions (such as Java 3D applications) is still undergoing changes and improvements. This is a bit of a mixed blessing since some of this work has been going on for about two years. However, the Java WebStart initiative demonstrates that Sun is taking the installation issue seriously. 311

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Figure 17.6 After installation the Java 2 plug-in

Filed under: Java 3D Programming — webmaster @ 6:09 pm

Figure 17.6 After installation the Java 2 plug-in icon will be available in the Windows Control Panel 17.2.4 Automatic Java 3D installation At the time of this writing it was not possible to confirm that Java 3D could be automatically installed by the Java 2 plug-in. Sun claims that this will work, but I experienced a number of problems running on Windows 98, which prevented me from verifying this. It should be possible to create a Java 3D applet that would install the Java 2 SDK, then install Java 3D and the Java 3D applet or application into the Java 2 extension directory and finally run the applet. There are a number of useful articles on Sun s web sites covering the Java 2 extension mechanism: Tutorial on the Java 2 extensions mechanism: http://java.sun.com/docs/books/tutorial/ext/index.html Java 2 SDK extensions documentation: http://java.sun.com/products/jdk/1.2/docs/guide/extensions/ 310

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

http://java.sun.com/products/plugin/1.3/converter.html After you have installed the plug-in,

Filed under: Java 3D Programming — webmaster @ 10:25 am

Figure 17.4 If the end user requires a newer JRE the Java plug-in installation will be activated Figure 17.5 The end user is prompted to select a download location and begin the download and installation process 309

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

http://java.sun.com/products/plugin/1.3/converter.html After you have installed the plug-in,

Filed under: Java 3D Programming — webmaster @ 10:25 am

http://java.sun.com/products/plugin/1.3/converter.html After you have installed the plug-in, you can invoke the HTML converter application and supply your original HTML file. The output from the conversion process will produce a file similar to the following: <!--"UNUSED PARAMETERS..."--> –> 17.2.3 The end-user experience When a user with a virgin machine hits your web page, the following sequence of steps will occur: 1. User prompted to install the correct version of the Java plug-in (figure 17.4). 2. User accepts and the plug-in installation process begins (figure 17.5). 3. Plug-in is installed and can be configured through the Windows Control Panel (figure 17.6). 308

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Figure 17.2 The SwingTest example running as an

Filed under: Java 3D Programming — webmaster @ 5:32 am

Figure 17.3 Running the HTMLConverter. Note the template file option allows you to tailor your converted files to particular operating systems or browsers 17.2.2 Using the Java 2 plug-in HTMLConverter To get the same applet to run with Internet Explorer or Netscape, your HTML page must first be converted to use the Java 2 plug-in. The HTML conversion process will take your original tags and wrap them in a web-browser plug-in tag. The original parameters will be passed to the plug-in instead of invoked directly on the applet. At the time of writing the latest version of the plug-in is: Java 2 SDK, Standard Edition (J2SE), Version 1.3.0_01 which also supports Netscape 6.0. The limitations of the plug-in tend to change quite quickly, here are some references: http://java.sun.com/products/plugin/ http://java.sun.com/products/plugin/1.3/docs/tags.html 307

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Figure 17.2 The SwingTest example running as an

Filed under: Java 3D Programming — webmaster @ 5:32 am

Figure 17.2 The SwingTest example running as an applet inside Internet Explorer. Note Java 2 plug-in Swing console and the Duke icon in the system tray 17.2.1 Original HTML applet code For example, when you are developing your applet you might have an HTML page like that shown in figure 17.3 to launch it. This HTML page would work fine with Sun s Java 2 applet viewer utility. 306

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

April 26, 2007

* native. Our menu items will be dropped

Filed under: Java 3D Programming — webmaster @ 11:08 pm

//Finally, make the parent frame visible! frame.setVisible( true ); } } 17.2 Adding support for running as an applet If you are running a flavor of Windows and you navigate to a web page that contains a Java applet (e.g., figure 17.2), the Java applet will be launched using the web browser s JVM. On a Windows machine, this will be the Microsoft VM, which does not implement the Java 2 (SDK 1.2) release of the J2SE platform. Your applets based on Java 2 will therefore not be started by the Microsoft VM. As the relationship between Sun and Microsoft has been a little frosty of late, it is unlikely that Sun can negotiate with Microsoft to get its JVM shipped with new installations of Windows. This has forced Sun to develop the Java plug-in product. The Java plug-in is a web-browser plug-in that installs on a Windows machine and can download the Java 2 JRE and launch a Java 2 JVM capable of running Java 2 applications. Because web-browser plug-ins can be installed with little user intervention by the web browser, the idea is that the installation and launch of the plug-in should be made as simple as possible. 305

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

* native. Our menu items will be dropped

Filed under: Java 3D Programming — webmaster @ 11:08 pm

* native. Our menu items will be dropped down in front of the * Java 3D Canvas3D so they must be created as heavyweight windows. */ JPopupMenu.setDefaultLightWeightPopupEnabled( false ); /* * Similarly we can declare that ToolTip windows are created * as heavyweight. Our application does not use tooltips. However, * if a toolbar was added the tooltips would overlap the Canvas3D * and would also need to be heavyweight windows. */ ToolTipManager ttm = ToolTipManager.sharedInstance(); ttm.setLightWeightPopupEnabled( false ); //Create the outermost frame for the application JFrame frame = new JFrame(); //Create the application JPanel, which contains the Canvas3D //with the 3D view. SwingTest swingTest = new SwingTest(); /* * Create a JMenuBar that will generate the events for the * application. We register the swingTest instance as a listener * for the action events generated by the menu items. */ JMenuBar menuBar = new JMenuBar(); JMenu menu = null; //Create some menu items and add them to the JMenuBar menu = new JMenu( “File” ); menu.add( swingTest.createMenuItem( “File”, “Save Image”, swingTest ) ); menu.add( swingTest.createMenuItem( “File”, “Exit”, swingTest ) ); menuBar.add( menu ); menu = new JMenu( “View” ); menu.add( swingTest.createMenuItem( “View”, “Cube”, swingTest ) ); menu.add( swingTest.createMenuItem( “View”, “Sphere”, swingTest ) ); menuBar.add( menu ); menu = new JMenu( “Rotate” ); menu.add( swingTest.createMenuItem( “Rotate”, “On”, swingTest ) ); menu.add( swingTest.createMenuItem( “Rotate”, “Off”, swingTest ) ); menuBar.add( menu ); //Assign the JMenuBar to the parent frame. frame.setJMenuBar( menuBar ); //Add the SwingTest JPanel to the parent frame. frame.getContentPane().add( swingTest ); //Set the initial size of the parent frame frame.setSize( 550, 550 ); //Register a window listener to intercept the closing //of the parent frame. registerWindowListener( frame ); 304

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

« Previous PageNext Page »

Powered by Java Web Hosting