Adding JApplet to JFrame?

Hi all,

I'm busy working on a java project for school; basically what I have is a JApplet, which is a little game I've developed, and a Swing GUI with options and the like...

At the moment I'm having trouble initializing the JApplet from the Swing GUI, my init code looks like this:

publicvoid gameInit ()

{

JApplet Slider =new SliderIMG2 ();

getContentPane ().add (Slider);

Slider.init ();

}

The first time I try to initialize it, nothing happens, then if I try again (I click on a button in my GUI that calls gameInit() ) I get the error "java.lang.OutOfMemoryError"

Please help!!

[805 byte] By [Hagena] at [2007-11-27 10:44:41]
# 1

wow sorry scrap that! The answer was much simpler than I thought :)

setContentPane (Slider);

That's all I had to change ... *Slaps forhead*

Hagena at 2007-7-28 20:08:20 > top of Java-index,Desktop,Core GUI APIs...
# 2

strictly speaking, that will work, but if your JFrame is going to have menus, then you are going to run into the old heavyweight/lightweight container issue.

I'm not sure if that's the only change, as getContentPane().add() and setContentPane() aren't much different.

bsampieria at 2007-7-28 20:08:20 > top of Java-index,Desktop,Core GUI APIs...
# 3

Well I havn't a clue why it works that way, and not with getContentPane().add

BTW Is there a way around that problem you speak of without complicating things too much?

I don't have any menus in my JApplet yet, but I might try add some soon... If I run into any trouble I'll know exactly where to turn for help :P

Message was edited by:

Hagen

Hagena at 2007-7-28 20:08:20 > top of Java-index,Desktop,Core GUI APIs...