Posted by
Juanjo Vega on
Jun 24, 2009; 12:43pm
URL: http://imagej.273.s1.nabble.com/help-tp3692012p3692013.html
To fix that you only need to declare the array as a class member and
inside the run() method you assign the memory to it. Something like:
class Result{
//Data fields...
}
public class Grid2 extends MouseAdapter implements PlugIn {
Result result[][]; // <<<--- I declare it, but it has no memory assigned yet.
public void run(String arg) {
int rows, cols;
// <<<< Here you get matrix size in some way: from a textfield, as a parameter at constructor, or whatever...
result = new Result[rows][cols]; // <<--- Now I assign memory for the matrix
for(int p=0;p<32;p++){
for(int q=0;q<32;q++){
result[p][q] = new Result();
}
}
//*other codes here....which uses This array result[32][32]*
}//*run() ends here*
/*/some other codes that uses result*
}//PlugIn ends here
I hope that helps, but that's not a problem with imageJ, that's plain
java ;)
Sincerelly,
Juanjo Vega.
ashish ram escribió:
> Hello everyone,
>
> I am a new user of imageJ and and presently using it first time for my
> project.For that i am writin codes for a plugin.I am facing a very basic
> programming difficulty and and i am unable to solve that.Here I am using an
> Array of Object which i have declared like ...
>
>
>
> class Result{
> //Data fields...
>
> }
> public class Grid2 extends MouseAdapter implements PlugIn {
> *Result result[][] = new Result[32][32];*
>
>
> public void run(String arg) {
>
> for(int p=0;p<32;p++){
> for(int q=0;q<32;q++){
> result[p][q] = new Result();
> }
> }
> //*other codes here....which uses This array result[32][32]*
> }//*run() ends here*
>
> /*/some other codes that uses result*
> }//PlugIn ends here
>
>
> this works nice for me.But i want that the array size is given by user
> during run time ,so need to be defined inside* run()*.But if i do that i
> loose my access over that array as soon as run() ends and can not use it
> outside it.I hope i am clear about my problem.*I want to access the array
> outside the run() block but at the same time declare it inside run().*
>
> Thank you all.
> Ashish
>
>
--
Juanjo Vega (
[hidden email])
Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.
http://www.cnb.csic.eshttp://www.biocomp.cnb.uam.es+34 91 585 4510
"Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes.