< Zurück | Inhalt | Weiter >

8.1.1 The user data field

A useful feature, defined in Shape3D’s SceneGraphObject base class, is that each Shape3D has a user data object associated with it. This allows an arbitrary Object−derived class to be attached to the Shape3D object using:

public void setUserData(java.lang.Object userData); public java.lang.Object getUserData();

The user data object can then be queried in response to scenegraph operations, for example selecting with the mouse. A selection utility will typically return the Shape3D object that was selected and an application−specific data structure will need to be retrieved to apply the results of the selection operation—this can be stored in the user data field of the Shape3D object.

The user data field can also be used to remove a scenegraph object once it has been added—a useful function. This technique is described in chapter 5.