Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum, where folks just love to get all messy with this GUI stuff...
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One other thing ....

what does this line
this.actionPanel = actionPanel;
do in this example?
[ February 15, 2004: Message edited by: Juhan Voolaid ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Reply
  • Bookmark Topic Watch Topic
  • New Topic