Hints image on the animation panel does not change.
Help I have several animation panels when the program initializes from the constructor. I have a separate AnimationPanel class that creates each panel for display. The initial 揾ello ?welcome panel (from the constructor) animates on the main panel when the program begins.
The problem is I want to have different animation panels (that are stored ) to animate and replace the main panel animation at a push of a button. While, the various panels can animate if called from the constructor, they do not animate when called from a button.
The buttons I created to switch the main animated panel with a different one seems to work to the extent that it gets the correct music, but the image on the animation panel does not change.
I know this is a more in depth of a question but might you be able to give me a point in the right direction?
Here is the code from the constructor that works fine in the constructor to start the main animation.
public PingPong()
{
// null layout because it has a main panel where this display panel is placed
super(null);
//panels are created
instantiatePanels();
//panels are added to the main content pane
placePanelsOnView();
startAnimation();
initializeAudio();
The problem is that I now start it with no animation to begin with and just an empty panel, but still when I try to add an animation from the button and it will not start. The contentPane is in a different class that places the buttons and the view together.
Here is the code that the button calls back with a getNextPanel() :
AnimatedPanel expertPingPongPlayerPanel
= new AnimatedPanel( );
add(expertPingPongPlayerPanel );
expertPingPongPlayerPanel.animate();
expertPingPongPlayerPanel.setVisible(true);
startAnimation();
AnimatedPanel is extending DisplayPanel which iself is an extention of JPanel.
DisplayPanel has:
public void paintComponent( Graphics g )
{
super.paintComponent( g );
// if pingPongANimation is ready to Paint
displayIcon.paintIcon( this, g, 0, 0 );
}
Ok, this answers 1 of my questions. But this code has nothing to do with the problem.
1. There is no need to call setVisible(true) on AnimatedPanel.
2. If AnimatedPanel is being added to a container (like JPanel) after it has been displayed you need to call revalidate() and repaint().
Try:
AnimatedPanel expertPingPongPlayerPanel = new AnimatedPanel();
add(expertPingPongPlayerPanel);
revalidate();
repaint();
expertPingPongPlayerPanel.animate();
startAnimation();
dwga at 2007-7-12 16:50:49 >

Actually...
public void paintComponent( Graphics g )
{
super.paintComponent( g );
// if pingPongAnimation is ready to Paint
imageIcon.paintIcon( this, g, 0, 0 );
}
You are correct that something needs to be done with how I write this code. I tired what you suggested and nothing happens. As mentioned, I now begin with nothing on the screen I push the button for it to begin to animate (with your updated code suggestion and still nothing happens).
I cannot figure why it works when it is created from a constructor, any further thoughts or other hints in the right direction? I appreciate your efforts?