I am creating a game of snake as an applet. What i am trying to acheive is that i draw a static background for the game only once in the content pane. To redraw the animation again and again, i am using the glass pane so that the background remains visible through it. Here are few lines of code:
pane = new Pane();
getContentPane().add(pane);
//pane.setVisible(true);
glassPane = new MyGlassPane();
setGlassPane(glassPane);
glassPane.setVisible(true);
//resize the screen
resize(appSize);
//setVisible(true);
:
:
class Pane extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
:
:
class MyGlassPane extends JPanel implements KeyListener
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
:
:
Here, Pane and MyGlassPane are two custom JPanels
However, when i try to make the glassPane visible as above, it hides the content pane and the background is not visble. I've tried all the combinations of 'setVisible' methods and reordered them in all the possible ways but nothing happens. If i don't set the glass pane's setVisible, then only content pane shows.
Disabling or enabling super.paintComponent()in both the classes doesen't help.
I need to get done with this project as soon as possible.
SOMEONE PLEASE HELPPPP!
[ April 01, 2003: Message edited by: Madhur Baheti ]
[ April 01, 2003: Message edited by: Madhur Baheti ]