RadioButton

RadioButton

Creates a clickable radio button with a label that can be selected by clicking. Radio buttons are assigned to a group and only one radio button in a group will be selected at any one time. You can get the text of the currently checked radio button in a group by calling RadioButtonGroup.getValueForGroup(group).

Constructor

# new RadioButton(parent, x, y, group, label, checked, defaultHandler)

Constructor
Parameters:
Name Type Description
parent HTMLElement The element to add this radio button to.
x number The x position of the radio button. Default 0.
y number The y position of the radio button. Default 0.
group string The group this radio button belongs to. Default "group".
label string The label of the radio button. Default empty string.
checked boolean The initial checked state of the radio button. Default false.
defaultHandler function A function that will handle the "click" event.
Example
const panel = new Panel(document.body, 20, 20, 200, 200);
const vbox = new VBox(panel, 20, 20, 10);
new RadioButton(vbox, 0, 0, "group", "Option 1", true, update);
new RadioButton(vbox, 0, 0, "group", "Option 2", false, update);
new RadioButton(vbox, 0, 0, "group", "Option 3", false, update);
function update() {
  console.log(RadioButtonGroup.getValueForGroup("group"));
}

Extends

Classes

RadioButton

Members

# checked

Sets and gets the checked state of the radio button.

# enabled

Sets and gets whether or not this component is enabled. Non-enabled components will be faded out and not respond to events.
Overrides:

# height

Sets and gets the height of this component.
Overrides:

# label

Sets and gets the label shown in the radio button's label.

# width

Sets and gets the width of this component.
Overrides:

# x

Sets and gets the x position of this component.
Overrides:

# y

Sets and gets the y position of this component.
Overrides:

Methods

# addHandler(handler)

Adds a handler function for the "click" event on this radio button.
Parameters:
Name Type Description
handler function A function that will handle the "click" event.
Returns:
This instance, suitable for chaining.

# bind(target, prop)

Automatically changes the value of a property on a target object with the main value of this component changes.
Parameters:
Name Type Description
target object The target object to change.
prop string The string name of a property on the target object.
Returns:
This instance, suitable for chaining.

# getChecked()

Returns:
whether or not the radiobutton is checked.

# getEnabled()

Gets whether the component is enabled.
Returns:
Whether or not the component is enabled.

# getHeight()

Gets the height of the component.
Overrides:
Returns:
The height of the component.

# getLabel()

Returns:
the text in the label.

# getWidth()

Gets the width of the component.
Overrides:
Returns:
The width of the component.

# getX()

Gets the x position of the component.
Overrides:
Returns:
The x position of the component.

# getY()

Gets the y position of the component.
Overrides:
Returns:
The y position of the component.

# move(x, y)

Moves the component to a specified position.
Parameters:
Name Type Description
x number The new x position of the component.
y number The new y position of the component.
Overrides:
Returns:
This instance, suitable for chaining.

# rotate(rad)

Rotates the component.
Parameters:
Name Type Description
rad number The number of radians to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# rotateDeg(deg)

Rotates the component.
Parameters:
Name Type Description
deg number The number of degrees to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# setChecked()

Sets the checked state of this radio button.
Returns:
This instance, suitable for chaining.

# setEnabled(enabled)

Sets the enabled state of this component.
Parameters:
Name Type Description
enabled boolean Whether or not the component will be enabled.
Returns:
This instance, suitable for chaining.

# setHeight(height)

Sets the height of this component.
Parameters:
Name Type Description
height number The height of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setLabel(label)

Sets the label of this radio button.
Parameters:
Name Type Description
label string The label to set on this radio button.
Returns:
this instance, suitable for chaining.

# setSize(w, h)

Sizes the component.
Parameters:
Name Type Description
w number The new width of the component.
h number The new height of the component.
Overrides:
Returns:
This instance, suitable for chaining.

# setWidth()

Does nothing. Width is set automatically based on the size of the check and label.
Overrides:
Returns:
This instance.

# setX(x)

Sets the x position of this component.
Parameters:
Name Type Description
x number The x position of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setY(y)

Sets the y position of this component.
Parameters:
Name Type Description
y number The y position of this component.
Overrides:
Returns:
this instance, suitable for chaining.