GlassPane over an Applet

131 views Asked by At

I've been working on a little Java project of mine and ofcourse I had to run into issues.

What i'm trying to do

I'm currently trying to use an applet and a glasspane in a JFrame. So I can draw on the glasspane instead of the applet (because I'm loading an external applet).

So my goal is to have a glasspane on top of the applet.

What is happening now?

Well, the glasspane only works when I remove the applet. It simply doesn't draw over the applet. Which is really strange.

Do you guys know what is going on? Your help is greatly appreciated.

public MainUI() {
    try {
        setLayout(new BorderLayout(0, 0));
        Loader loader = new Loader();
        loader.getUrl();
        game = loader.loadGame();
        game.setPreferredSize(new Dimension(765, 503));
        game.setVisible(true);

        getContentPane().add(game);

        JPanel panel = new JPanel() {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            public void paintComponent(Graphics g)  
               {  
                  g.setColor(Color.red);  

                  //Draw an oval in the panel  
                  g.drawString("Hello World!", 10, 10);  
               }  
        };
        setGlassPane(panel);
        panel.setVisible(true);
        panel.setOpaque(false);
        getContentPane().setPreferredSize(new Dimension(765, 503));

        pack();
        revalidate();
        repaint();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
0

There are 0 answers