I am trying to pass a variable in From a form to a class in Sun ONE studio
Printable View
I am trying to pass a variable in From a form to a class in Sun ONE studio
A form is a class too.
What do you mean by pass? If you're in the class' code and want to access a variable of the form you need a reference to the form and an accessor function for the member. If you're in the form's code and want to create an instance of the class and give it the variable, you need to pass it to the constructor. If you already have an instance of the class you could call a setter function for a property of class or pass it to individual methods you call.
What kind of variable is it also? Reference or Primitive? As CornedBee pointed out in his suggestion, if you are in the form code you can simply create an instance of the class and pass the variable via the class constructor. I usualy use this method which is somtimes refered to as Aggregation. I often use Aggregation when i need a class to be able to invoke a method back on the class that was passed in as a reference. For primitive values that need to be passed in and modified i just define setter methods within my class while keeping the class members private as to keep everything properly encapsulated.