• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Urgent: Glass Pane is Opaque!!

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the constructor for the glass pane, simply call setOpaque( false );
 
Madhur Baheti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A MILLION Thanks!!!
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic