darn it … I had been really such a fool during these three days. I admit I am really a newbie again in Java programming after leaving it for four years since my way to fashion design back then. totally blank again and got lost in reading the Java documentation.
here was my problem:
I was creating a customized JInternalFrame singleton class (I named it dwInternalFrame class) which would be my global class for customized JInternalFrame to receive any customizable JPanel via a parameter pnContent (a JPanel) as its content pane. I was planning to only create many customized JPanel (e.g. pnNewMaster for adding new data, pnEditMaster for editing the table data, etc.) and then I would only call the constructor of dwInternalFrame and pass the customized JPanel (for example that pnNewMaster) into this dwInternalFrame constructor like:
dwInternalFrame ifNewMaster = dwInternalFrame("Adding new Warehouse", pnNewMaster);
but later, there was a JButton btClose for closing the dwInternalFrame that contained this pnNewMaster. how to do that …? I had done a lot of modification to the constructor, create new methods for passing the dwInternalFrame variable name (in this case I called it ifNewMaster) into the pnNewMaster method like:
which would be passed into pnNewMaster’s myContainer, so it would recognize ifNewMaster when I had to close it via clicking btClose.
still, I got the java.lang.NullPointerException when I tried to close the ifNewMaster. what’s up? I did the debugging and found out that the ifNewMaster I passed as the parameter was null for the pnNewMaster, when I recalled the hidden ifNewMaster.
that’s why this code would raise the null exception when I clicked the btClose:
this one raised the same null exception too:
so much effort searching the Java Documentation and googling for the proper way to do the btClose clicking, only to find out I was such a fool to not recognize it this way:
a very simple one liner to solve my three days problem. I don’t even need any ifNewMaster as parameter passing to the pnNewMaster class nor method. darn it. the JRootPane was the root panel for the frame like component, how could I forget it?! and when I call getParent() for the RootPane of pnNewMaster (my customized JPanel), of course I would get the ifNewMaster (aka the dwInternalFrame). darn it. I should learn to read the Java documentation any better.
and when I called the dispose(); for the ifNewMaster or something like that (or any of my dwInternalFrame) . I found out that after I dispose the ifNewMaster, I couldn’t call it again for the second time. what’s happened???
finally I found out, I should have set the dwInternalFrame this way when I created it:
and to not call the dispose(); from the pnNewMaster’s btCloseActionPerformed (as I did the clicking to the btClose), instead I should do the setVisible(false); like in
so the singleton would still be able to be called again. why I should have done this, I still need explanation, I just found it this way and I don’t know why if my JInternalFrame singleton was disposed, I couldn’t call it again with a new dwInternalFrame(…) such like that.
any suggestion for a better way doing this things, Guys? or any URL out there providing the tips? I don’t think I’ve done it properly yet, I still need some advice about singleton JInternalFrame thingy.
I have coding too much Delphi programming for the past year, I guess. completely blank in Java again. hmm … migrating from one programming language to another is not as easy as translating a real language. I should get a grip on my Java books again …
thank you for coming and dropping any comments / suggestions.
for those already in Friday noon and not working on Shabbat (Saturday)
may you have a nice weekend and rest.