Class myphysicslab.lab.util.ParameterNumber

Provided By
All Implemented Interfaces

Provides access to a numeric value of a Subject. Has options for setting number of significant digits to show, and upper/lower limit on value. Default is 3 significant digits, lower limit of zero, and upper limit is infinity. See myphysicslab.lab.util.Parameter for more documentation.

How to Represent an Enum

To create a ParameterNumber that represents a numeric enum requires some extra code for satisfying the compiler about the conversion between number and enum. Here is an example from myphysicslab.lab.graph.GraphLine (NOTE: this has since changed to be a ParameterString).

new ParameterNumber(this, GraphLine.en.DRAWING_MODE,
  (/** function(this:myphysicslab.lab.graph.GraphLine, number) * /
  (function(n) { this.setDrawingMode(DrawingMode.numberToEnum(n)); })),
  DrawingMode.getChoices(), DrawingMode.getValues());

This defines a special 'setter' function because setDrawingMode takes an argument of the enum type DrawingMode, not of type number. (The code example uses a closure compiler 'type cast': the type is in a comment followed by the object in parenthesis.)

See Enums for more information.

new ParameterNumber( subject, name, localName, getter, setter, opt_choices, opt_values )


the Subject whose value this ParameterNumber represents


the name of this Parameter; this will be underscorized so the English name can be passed in here. See myphysicslab.lab.util.UtilityCore#toName.


the localized name of this Parameter

getterfunction(this: myphysicslab.lab.util.Subject): number

A method of subject with no arguments that returns the value of this Parameter

setterfunction(this: myphysicslab.lab.util.Subject, number): ?

A method of subject with one argument that sets the value of this Parameter


the translated localized strings corresponding to the values (optional)


the numbers corresponding to the choices that the parameter can be set to (optional). When specified, only these values are allowed.

Instance Methods