Scripting Guide > Display Trees > Construct Custom Windows > Send Messages to Constructed Displays
Publication date: 07/08/2024

Send Messages to Constructed Displays

When you assign a constructed display to a name, that name becomes a reference to the window, which in turn owns the display boxes inside it. Using subscripts, you can then send messages to the display boxes inside the window.

For example, the following script creates an interactive sine wave graph. The script automates the interaction by sending messages to the frame box inside the window. Note the frame box assignment to tf in the middle of the script).

amplitude = 1;
freq = 1;
phase = 0;
win = New Window( "Wiggle Wave",
	Graph Box(
		Frame Size( 500, 300 ),
		X Scale( -5, 5 ),
		Y Scale( -5, 5 ),
		Y Function( amplitude * Sine( x / freq + phase ), x );
		Handle(
 

/* current values of phase and amplitude position

the square handle.

script begins after the last comma after amplitude */

			phase,
			amplitude,
 

/* x and y have been set to the handle’s position

but the handle doesn’t move unless the values specified

in the first two arguments are updated */

			phase = x;
			amplitude = y;
		);
 

// Handle works similarly except that the y value is .5

		Handle( freq, .5, freq = x );
 
		Text( // display a text string in the graph
			{3, 4},
			"amplitude: ",
			Round( amplitude, 4 ), // display the current value
			{3, 3.5},
			"frequency: ",
			Round( freq, 4 ), // display the current value
			{3, 3},
			"phase: ",
			Round( phase, 4 ) // display the current value
		);
	)
);
tf = win[Frame Box( 1 )]; // get the frame box (the graph)
For( amplitude = -4, amplitude < 4, amplitude += .1,// animate the amplitude
	tf << Reshow // force the graph to update
);
amplitude = 1; // use for loops for more complex movement
freq = 1;
phase = 0;
For( i = 0, i < 1000, i++,
	amplitude += (Random Uniform() - .5);
	amplitude = If(
		amplitude > 4, 4,
		amplitude < -4, -4,
		amplitude
	);
	freq += (Random Uniform() - .5) / 20;
	phase += (Random Uniform() - .5) / 10;
	tf << Reshow;
	Wait( .05 );
);
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).