In which method are you doing your painting?
If you use Swing, put your painting code in paintComponent, and you
don't have to care about repainting when the window is hidden,
minimized or whatever. Just call repaint() when your data changes.
Hope that helps
Norbert
"Raous" <chareraous@hotmail.com> wrote in news:1132207548.714495.249500
@g44g2000cwa.googlegroups.com:
> Hello,
> I created a program which draws elipses on some panels.
[quoted text clipped - 14 lines]
>
> Could anyone help me?
You don't need to bother with componentShown, unless you want to do
something funky with your component (as a stupid example, if you want to
play a sound file every time a component is shown, you will need to
implement ComponentListener). Failing that, just trust java to call the
correct method to paint your component.
For example, you can write a simple subclass of JPanel that will draw an
oval on itself like this:
class OvalPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawOval(10, 10, getWidht()-10, getHeight()-10);
}
}
If you're using awt, the above code becomes
class OvalPanel extends Panel
{
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.BLUE);
g.drawOval(10, 10, getWidht()-10, getHeight()-10);
}
}
As you can see, you don't need to call repaint() or bother with the
ComponentListener interface. You only need repaint() if you want to
change what is drawn on the panel.
Also, I noticed you said "each Panel", while you were talking about
JButton and JLabel earlier. Panel is an awt component, while JButton and
JLabel are swing. While it is theoretically perfectly ok to mix swing
and awt, it's usually not a great idea. So instead of Panel, use JPanel.
As an aside, WM_PAINT is part of the Windows API, and not specifically
for VC++.