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

How to access?

 
Robert Ploch
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Imagine i had these classes:
class myApplet extends JApplet{
JPanel x = new myPanel();
JPanel y = new my2Panel();
}
class myPanel extends JPanel {
JButton button = new JButton();
}

class my2Panel extends JPanel {
draw();
}

Now when a user hits the button in myPanel, can i directly access the draw-method in my2Panel?
I would try using the getContentPane()-method, but dont know if it works and how...
Is it possible?
Maybe this diagram would help, this is the big brother of the situation described above:
http://www.robertploch.de/Files/diagram.pdf
(in the diagram it is Gui=myApplet and the surrounding Panels are myPanel,my2Panel and so on)
With regards
Robert Ploch
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you define your draw method as:



You could do my2Panel.draw().
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your other option would be to do something like:



And this way would probably be preferred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic