Hi I have a simple problem, but i don't know how to solve it. The situation is: Program has main class Hero and the constructor Hero() where are several panels. One panel has buttons. Each panel is defined in inner class. Now i want to do so that, if i press button from lets say buttonPanel i want to see something happening in other panel - lets say actionPanel. Problem is that when i press button - actionPanel must be refreshed - to do that i must call actionPanel constructor i think. Hohh ... this is creazy to explain ... i write a little code below ... try to make sense of that and correct me
I hope u get the idea and know to give me some advice or something....
One way to do this is to give (pass) an ActionPanel reference (namely, actionPanel) to the ButtonPanel class so ButtonPanel can call methods inside ActionPanel. So we pass the reference to the constructor when we instantiate (create an instance of) ButtonPanel. Now the buttons in ButtonPanel can use the reference to call methods inside ActionPanel.
It assigns the value of local variable named "actionPanel" (that was passed in as a parameter to the constructor), to the member variable named "actionPanel" that is defined asa part of the ButtonPanel class. The "this" keyword lets you access object-level or class-level attributes and methods of the current object.
OK ... ive got new problems that i can't find answers. It is with this same example so i continue with this topic. OK after i changed my program a bit it still doesen't work. When i push a button - this action panel will be blank. But to the console in backround appers lot of stuff ... something about: java.lang.nullpointer exception lot of stuff about action performed things and what i think is the most important - EventDispatchThread In this example i didn't use any threads (didn't think it's neccesary) - so i have no idea what should i do next. I think it enaugh if i give u code about 2 classes this buttonPanel and actionPanel - but in my example they are buttonPanel=b and infopanel=i hope u understand and can help me. Here is the code:
Post by:autobot
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
a bit of art, as a gift, the permaculture playing cards