DirectX Media for Animation Java Reference |
![]() Previous |
![]() Classes |
![]() Index |
![]() Next |
public class TextBvr extends Behavior { // Methods public TextBvr bold(); public TextBvr color(ColorBvr col); public TextBvr font(FontfamilyBvr font); public TextBvr font(StringBvr name); public TextBvr italic(); public ImageBvr render(); public static TextBvr newUninitBvr(); public static TextBvr simpleText(StringBvr str); }
Creates an object that represents a text behavior. The behavior consists of a string behavior that defines the characters to display and attributes that define the appearance of these characters.
Text attributes include the font (typeface), color, and whether the text is bold or italic or both. The size of the text is not an attribute. Instead, you set the text size by rendering the text and scaling or transforming the resulting image.
public TextBvr bold();Creates a bold text behavior from an existing behavior.
Return Value:
Returns the TextBvr object.
public TextBvr color(ColorBvr col);Creates a text behavior that is the result of applying the given color behavior to the existing behavior.
Return Value:
Returns the TextBvr object.
Parameter Description col The ColorBvr object identifying the color to apply to the text when rendered.
public TextBvr font(FontfamilyBvr font);Creates a text behavior that is the result of applying the given font behavior to the existing behavior.
Return Value:
Returns the TextBvr object.
Parameter Description font The FontfamilyBvr object identifying the font to apply to the text when rendered.
public TextBvr font(StringBvr name);Allows fonts other than FontfamilyBvr objects to be used.
The following example creates an applet displaying the text "Hello World" on a solid black background. The font changes once per second. Initially, it is Times New Roman. It then changes to Symbol, Arial Black, and Verdana. After Verdana, it returns to Times New Roman and the cycle begins again.
import com.ms.dxmedia.*; class FontTestModel extends Model { public void createModel(double startTime, BehaviorCtx ctx) { DXMEvent t = timer(toBvr(1)); StringBvr f = StringBvr.newUninitBvr(); f.init(until(toBvr("Times New Roman"), t, until(toBvr("Symbol"), t, until(toBvr("Arial Black"), t, until(toBvr("Verdana"), t, f))))); ImageBvr model = overlay(simpleText(toBvr("Hello World")).font(f).render(), solidColorImage(black)); setImage(model); } } public class FontTest extends DXMApplet { public void init() { // Always call the superclass's init() first to ensure codeBase is set super.init(); // Now set the model setModel(new FontTestModel()); } }Return Value:
Returns the TextBvr object.
Parameter Description name The name of the font to apply to the text when rendered.
public TextBvr italic();Creates an italic text behavior from an existing behavior.
Return Value:
Returns the TextBvr object.
public ImageBvr render();Creates an image behavior that consists of the characters on the text behavior, displayed using the behavior's current font, color, and other attributes. The text is centered around (0,0) in the image. The resultant image is transparent in all places other than where the text is actually rendered. There are no alignment operators such as center or align left. Instead, these are achieved by transforming the image. The bounding box of rendered text is the axis-aligned bounding box of the rendering of that text, which will be centered at the origin.
Return Value:
Returns the ImageBvr object.
public static TextBvr newUninitBvr();This method allows you to refer to an TextBvr behavior before that behavior has been defined. With this method you can create the behavior and use it in the definition of other behaviors, but not actually define its contents until some later point. (This is accomplished with the init method, which is available on all behaviors.) The system generates a run-time error if you initialize a non-uninitialized behavior, initialize an uninitialized behavior that has already been initialized, or run an initialized behavior that has not yet been initialized.
Return Value:
Returns the TextBvr object.
public static TextBvr simpleText(StringBvr str);Creates a text behavior that consists of a given string. By default, the text color is white, the font is a serif proportional font, and the text is neither bold nor italic. The default text size is dependent on the user's system settings. For example, default text on a system whose display is set for "small fonts" will be a different size than on a system whose display is set for "large fonts."
Return Value:
Returns the TextBvr object.
Parameter Description str The StringBvr object representing the characters in the text.
© 1997 Microsoft Corporation. All rights reserved. Legal Notices.