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();

[1286 byte] By [peacerosetxa] at [2007-11-27 6:05:13]
# 1
Can't help you without seeing the code for the buttons action handler.My guess though is that you need to add a calls revalidate() and repaint().
dwga at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...
# 2
thank you dwg.I read about revalidate() I will read up on it now. You are very kind! I will try it and post if it works.
peacerosetxa at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...
# 3

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();

peacerosetxa at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...
# 4
Ok, this is still not enough information.Where is this code being called, i.e. to what is the expertPingPongPlayerPanel being added?What is AnimatedPanel extending? The name suggests JPanel in which case calling setVisible will not help.
dwga at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...
# 5

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 );

}

peacerosetxa at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...
# 6

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 > top of Java-index,Java Essentials,New To Java...
# 7

Actually...

public void paintComponent( Graphics g )

{

super.paintComponent( g );

// if pingPongAnimation is ready to Paint

imageIcon.paintIcon( this, g, 0, 0 );

}

peacerosetxa at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...
# 8

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?

peacerosetxa at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...
# 9
Just figured I would write a solution that worked for me. I used the CardLayout.Cheers!
peacerosetxa at 2007-7-12 16:50:49 > top of Java-index,Java Essentials,New To Java...