Swing and GlassPane for games
Hi all!
I wonder if it is posible to have two/three GlassPanes over eachother for use i games etc.
I have tried this and used two gifs, but every time the panes seems to melt togheter, making the gifs come side by side instead of one over the other.
It looks like they have become the same GlassPane.
The strange thing is tough, that if i add a third layer with the same pic as layer 2, the pic seems to write over the layer 2, just like i want to, but it seems only to work with the same gif pic :S
I am using, SWING, can I do what I want with that, or is there another way thats better and easier?
Can someone pleas help me?
And please go easy on me i am kind of a newbie. :(
CODE:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.net.*;
public class Fonster extends JFrame{
//This test contains 3 layers.
//But the third layer seems to overlapp the second, is this
//becouse the have the same gif?
JPanel pan1 = new JPanel();
JPanel Layer1 = (JPanel) this.getGlassPane();
JPanel Layer2 = (JPanel) this.getGlassPane();
JPanel Layer3 = (JPanel) this.getGlassPane();
JScrollPane GameWin = new JScrollPane(pan1);
Image sand = Toolkit.getDefaultToolkit().getImage("sand.gif");
Image grass = Toolkit.getDefaultToolkit().getImage("grass.gif");
JLabel tile = new JLabel(new ImageIcon(sand));
JLabel tile2 = new JLabel(new ImageIcon(grass));
public Fonster(){
Container c = getContentPane();
c.setLayout(new FlowLayout());
pan1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
pan1.setPreferredSize(new Dimension(800, 600));
pan1.setMinimumSize(pan1.getPreferredSize());
pan1.setMaximumSize(pan1.getPreferredSize());
pan1.setAlignmentX(RIGHT_ALIGNMENT);
pan1.setBackground(Color.white);
pan1.setOpaque(true);
Layer1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
c.add(GameWin);
pan1.add(Layer1);
Layer1.add(tile);
pan1.add(Layer2);
pan1.add(Layer3);
Layer1.setVisible(true);
Layer2.setVisible(true);
Layer3.setVisible(true);
Layer2.add(tile2);
Layer3.setVisible(true);
Layer3.add(tile);
setSize(800, 600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args){
Fonster c1 = new Fonster();
}
}
:END CODE

