• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel/JApplet Communication  RSS feed

 
Ernie Wilder
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a question.
I've created a class called ControlPanel.
It extends JPanel.
I've added it to the South region of a JApplet using BorderLayout.
ControlPanel contains a button called cmdAnimate

cmdAnimate.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
animateAngle(100);
}
});
Now, the method animateAngle is in the public class of the containing JApplet.

How do I refer to this method properly??
Is there like a getParentNode() method or something that allows the button's underlying panel to communicate with the JApplet..
Please help..
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If ControlPanel is not an inner class of MyApplet,
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == button)
{
((MyApplet) getApplet(button)).animateAngle(100);
}
}
private Container getApplet(Container comp)
{
if(comp.getParent() instanceof MyApplet)
{
return comp.getParent();
}
return getApplet(comp.getParent());
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!