I have a gameboard class: class gameboard extends JInternalFrame

In the constructor i have the line: setDefaultCloseOperation(DISPOSE_ON_CLOSE);

my gameboards are actually in an array myboards[500] were each is an object of this class.

the deal is I want to be able to tell which are open and i want to resuse spots in the array if they close a window. I thought if they closed a gameboard, the array spot would go to null. It does not. The only way to tell if a board spot in the array is open is:

if(myboards[a].isVisible() == true).

Am I doing this right? if it properly disposes of the game board should the spot myboards[a] == null? Can i just stick with isVisible and if say spot 0 is not visible its safe to to do myboards[0]= new gameboard(); ?

can you even call isVisible() on spots in teh array that were never initialized in the first place?

Mike

> can you even call isVisible() on spots in teh array that were never initialized in the first place?
You would have to put in a null check first, but since if() statements short-circuit on failure, it could still be one statement

if( boards[1]!=null  && ! boards[1].isVisible() ){

I would recommend removing the dead references though. I'd also recommend using a List instead of an array to hold the board refs.

Edited 6 Years Ago by Ezzaral: n/a

i'm doing regular checks on the array in the telnet class to send game info to the right boards, if its not visible, and i first check its not null, then its safe for me to just set it to null? there is constant chatter back and forth that the telnet class is involved in so it can handle cleanup without listeners. there is no great need to update boards to null immediately, if it takes a minute that is fine. these are macro events in the program.

the second isssue is if setDefaultCloseOperation(DISPOSE_ON_CLOSE);
that i set in consturtor isnt setting the array spot to null, what's happening to the object? is my array just not updated that its null, or is the object persisting. though i know it can persist tell garbage collection happens. I dont have a close function in the game class. only that line i set up the set default close operation in the constructor.

Mike

dispose() does not destroy an object, it releases any native graphical resources related to the display of that component. It will have no effect on those references that you have stored in your board array. That is why you need to put in some cleanup code when the board closes that notifies the main controller to drop the reference. To make sure it gets called no matter how the user closes the frame, a frame listener is probably your best bet.

Edited 6 Years Ago by Ezzaral: n/a

one of the next things i'm going to move onto is handling proper disposing via the onclose hanldler. If i have specific questoins i'll start a new thread on how to use onclose, but for now this is solved.

This question has already been answered. Start a new discussion instead.