Button

The control that is commonly used to enable a user to interactively influence the model. You can define a specific action (in the button's Action property) that will be performed every time the user clicks the button at the model runtime.

Simple demo model: Buttons Change Parameter Value

 To add a button

  1. Drag the  Button element from the  Controls palette into the graphical editor.
  2. Navigate to the button's properties.
  3. Type the text that you want to be displayed inside the button in the Label field. Optionally you can customize the text appearance (font, size, etc.) in the Appearance section.
  4. Type the Java code (that you want to be executed on clicking this button) in the Action section of the button's Properties. Make sure you terminate each line of the code with a semicolon.

Properties

General

Name – The name of the button. It is used to identify and access the control from code.

Ignore – If selected, the button will be excluded from the model.

Visible on upper level – If selected, the control will be also visible on the upper level where this agent lives.

Label – Here you can specify the text of the label displayed on the button.

Enabled – Here you can specify Boolean expression determining whether the button is enabled or disabled.

Action

Here you can type the code to execute when the button is pressed.

Appearance
Background color – The control specifies the background color for the button. Click inside the control and choose a color from the set of the most used ones, or choose a custom color using the Colors dialog box.
Background color is correctly displayed under Windows with Classic appearance. However, certain operating systems do not support buttons with user-defined background colors (Windows XP with XP-style appearance, Windows Vista with Windows Vista Basic or Windows Aero appearance).

Text color – The control specifies the color of the label's text. Click inside the control and choose a color from the set of the most used ones, or choose some custom color using the Colors dialog box.

Font – Specifies the font family for the label's text. You can adjust the size of the text in the field to the right (pt.).

Italic – If selected, the label's text will be italicized.

Bold – If selected, the label's text will be emphasized in bold.

Position and size

X – X-coordinate of the button's upper left corner.

Y – Y-coordinate of the button's upper left corner.

Width – The width of the button (in pixels).

Height – The height of the button (in pixels).

Advanced

Visible – The control's visibility.  The control is visible when the specified expression evaluates to true, otherwise it is not visible.

Replication – Here you specify the number copies of this control you want to be created. If you leave this field empty, only one such control will be created.

Show name – If selected, the button's name will be displayed on the presentation diagram.

Icon – If selected, the button will be considered as a part of the agent's icon.

Functions

Enabling/disabling the button

Function

Description

boolean isEnabled()

Tests if the button is enabled or disabled. Returns true if enabled, otherwise false.

void setEnabled
(boolean yes)

Sets the control enabled or disabled.

Parameter:
yes - If true, the control will be enabled, if false - disabled. 

Executing the button's action programmatically

Function

Description

void action()

Executes the action associated with the button.

Label text

Function

Description

String getText()

Returns the button label text.

void setText(Object text)

Sets the button label text.

Parameter:
text - the new label text

Button position

Function

Description

double getX()

Returns the X coordinate of the control (namely, the X coordinate of its upper left corner).

double getY()

Returns the Y coordinate of the control (namely, the Y coordinate of its upper left corner).

void setX(double x)

Sets the X coordinate of the button.

Parameter:
x - the new value of X coordinate

void setY(double y)

Sets the Y coordinate of the button.

Parameter:
y - the new value of Y coordinate

void setPos(double x,
double y)

Sets new coordinates for the control.

Parameters:
x - the new value of x coordinate
y - the new value of y coordinate

Button size

Function

Description

double getWidth()

Returns the width of the button in pixels.

double getHeight()

Returns the height of the button in pixels.

void setWidth(double width)

Sets the width of the button equal to width.

void setHeight(double height)

Sets the height of the button equal to height.

Button visibility

Function

Description

boolean isVisible()

Returns the visibility of the button.

void setVisible(boolean v)

Sets the visibility of the button.

Parameter:

v - visibility: if true - the button is set to be visible, if false - not visible.


Related topics

 Aligning shapes

 API Reference: ShapeButton Class