Forums Register Login

i want to call main class constructor from inner class or smt...

+Pie Number of slices to send: Send
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....
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Moving this to the Swing / JFC / AWT forum, where folks just love to get all messy with this GUI stuff...
+Pie Number of slices to send: Send
Thank you, thank you very much for such a good answer to such a messy question Craig Wood!!!
I feel i jsut gained a level in Java because of u
+Pie Number of slices to send: Send
One other thing ....

what does this line
this.actionPanel = actionPanel;
do in this example?
[ February 15, 2004: Message edited by: Juhan Voolaid ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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:

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
https://gardener-gift.com


reply
reply
This thread has been viewed 1680 times.
Similar Threads
Won't Display
GUI with inner classes problem...
Problem with ActionPerformed
addActionListener problem
Applet timer
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:39:43.