APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

view.print(String message) method post and replies

Return to the view.print(String message) method thread
Login to post to this thread

view.print() method for multiple text areas
Alberto Porras
5 Posts

I've recently started programming with EjsS and one of the problems I've come across is when using multiple text areas for displaying strings. As far as I know, you have two predefined methods: _view.print() and _view.println() which enables you to print a string in the last text area created. But, what code or method would you use for displaying text strings in text areas created before the last one, for which both aforementioned methods don't work?
I have tried using view.print(), but I might be doing something wrong...

Thank you in advance!


Replies to view.print() method for multiple text areas

Re: view.print() method for multiple text areas -
lookang Avatar
lookang
222 Posts

You could assign boolean variables such as show displacement to be turn true or false depending on whether it is as you designed, to show that variable drawing.


See my example
http://iwant2study.org/ospsg/index.php/interactive-resources/physics/01-measurements/19-decomposition-of-vector-any-mutually-perpendicular-advance-model

Attached File: Screenshot_20160418-062507.png


OSP@SG blog
OSP@SG Digital Library


Re: Re: view.print() method for multiple text areas -
Alberto Porras
5 Posts

Thank you for your reply. Nevertheless, I don't quite understand your method...
The thing is, you have two text areas: text area A and text area B, in which you want do display string A and string B (string A in text area A and string B in text area B). The last text area created was text area B. Therefore, if I use _view.print(string A) the string would be displayed in text area B, because it's the last one created.
What code would you then use to display string A in text area A?
If I look at the properties of a text area, you can't assing it any variables, just its title, if it's editable or not, its visibility, etc.

Again, thank you for your effort!



Re: view.print() method for multiple text areas -
Francisco Esquembre
228 Posts

Hi,

Suppose the text area view element you want to print to is called textAreaA, then use:

_view.textAreaA.println ("Whatever");

or

_view.textAreaA.print ("Whatever");

That should do.

Paco

Post edited April 19, 2016 at 12:42 PM EST.



Re: Re: view.print() method for multiple text areas -
Alberto Porras
5 Posts

Hi, Paco,

I have a text area called "Operations", and I have tried using both print a and println the same way you did to print in the string "TEST". In both cases I got errors, for which I send you pictures of the corresponding messages.

What did I wrong this time? Could it be that I have to define the "Operations" text area as an object in the variables tab?

Thank you!

Alberto

Edit: I have come up with two solutions, the first one being _view.TextArea.setText("whatever"), which prints and deletes the previous strings printed in the same text area, and _view.TextArea.append("whatever"). In any case, I would still like to know what could be the reasons the previous methods have failed, in order to learn and improve for future occasions. Thank you in advance!

Post edited April 19, 2016 at 2:28 PM EST.

Attached File: errorprint.jpg



Re: Re: Re: view.print() method for multiple text areas -
Francisco Esquembre
228 Posts

Hi

The message says you have no view element called Operations. Please, send the .ejs file.

Paco



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book