I have a java class in which I constructed an applet. This file is compiled & when executed displays a blank applet. Now I have another java class in which I am contructing a JPanel. I want to add this JPanel to my applet for which I use this code:
The last line add(content); gives a compilation error. It says "cannot resolve symbol, symbol: method add()" Can anyone please tell me whats going wrong?? And what can I do instead?
Applet is an indirect subclass of Container, so the method should be there. Does your class extend Applet or JApplet?
If it is a JApplet you want to use getContentPane() like Campbell suggested, or you will get a runtime exception when used in Java 1.4 or before. Only since Java 5 does JApplet (and JFrame and JDialog) redirect the container specific methods (adding, removing, layouts) to its content pane.
Thankyou for responding. My class is extending JApplet. I am using java1.4 so that shouldnt be a problem. Where should I use the getcontentpane() method & how. How do I use it to send the content of my panel to the Applet.
I have a java class in which I constructed an applet. This file is compiled & when executed displays a blank applet.
This sounds suspicious. How do you "construct" an applet? Applets should not have a constructor (besides the default no-arg constructor), nor should code of yours ever call it. That's for the browser JVM to do.
If this is not an applet that's intended to run in a web browser, then you're asking for trouble subclassing Applet or JApplet.