Re: ImageJ/Java Question
Posted by
dscho on
Oct 02, 2009; 6:08am
URL: http://imagej.273.s1.nabble.com/ImageJ-Java-Question-tp3690936p3690940.html
Hi,
On Thu, 1 Oct 2009, David William Webster wrote:
> I ran into the situation desribed below, but don't understand Java well
> enough to know why what I'm doing is done this way. For what it's worth,
> I suspect I could do what I want to do easier using Stacks.
>
> I have an array of 5 ImageProcessor objects called ip. I want to display
> each object in turn using a loop. So first I declare an array of
> ImagePlus objects, called im. This is shown below. But, the array
> entries ar all null at this point. So, in the in the loop I again use
> new and an ImagePlus constructor to create an ImagePlus object, im[k],
> My question is can this be done without using "new" twice and/or is this
> correct.
>
>
> ImagePlus im[] = new ImagePlus[5];
>
> for(int k = 0; k < 5; k++)
> {
> im[k] = new ImagePlus();
>
> im[k].setProcessor("name",ip[k]);
> im[k].show();
> }
You have to use the "new" operator twice. Why? Because you are
instantiating two _different_ types of classes. One is and array, and one
is and ImagePlus.
Ciao,
Johannes