• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array of Objects

 
Alireza Bahmanpour
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a class Pixel(x, y, filled) which holds the properties of a single pixel in a BufferedImage. x and y are simply the coordinates, and 'filled' is a boolean that specifies whether the pixel is filled or not (its really long to explain the whole thing, so this is just to give you an idea of what's going on)

Now I want to create a 2d array the size of my BufferedImage (Pixel[][] pixelArray = new Pixel[width][height]), holding a new Pixel object in each cell with its own properties. Is it possible to use the following for-loop for this matter? Or do I have to change the name of the Pixel object every time?




Thanks in advance
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to use the following for-loop for this matter?

Yes. It looks fine.

Or do I have to change the name of the Pixel object every time?

The name ? Which name ? Why would you give it a name ?
 
Alireza Bahmanpour
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After testing it, I still don't get what I want!
All the elements of the array are still null

Any suggestions?
 
Henry Wong
author
Marshal
Pie
Posts: 22103
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alireza Bahmanpour wrote:After testing it, I still don't get what I want!
All the elements of the array are still null


The only way for it to be all null is if you didn't set it. And the only way that I can see that happen is if width and height isn't set properly.

Henry
 
Evan Caballero
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your code should work fine. Could you show us what code you have writen before and after the 'for' loop ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic