I have try to run a program of JApplet as JFrame, but it didn't works. Can someone help me?Thanks.

public class MyApplet extends JApplet{

//have some coding here

class display extends JPanel{
//have some coding here

public static void main(String [] arg){
	JFrame frame = new JFrame("MyApplet");
	MyApplet applet = new MyApplet();




it didn't work

Please explain.

Its best to setVisible after everything has been added to the frame.

To convert an applet to an application, treat the applet's GUI code as a panel (Which applet extends) and add that to the frame. Then add calls to the applet's methods that are called by the browser: init and start.
If the applet uses any AppletContext methods, you will need to provide them to the applet.

Edited 6 Years Ago by NormR1: n/a

Ok, its mean that my sounds clip and images didn't show up when I run it. And I try to add the applet.init() but it turns out to be an error message. Is like below :

Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getDocumentBase(Unknown Source)
at MyApplet.init(MyApplet.java:93)
at MyApplet.main(MyApplet.java:161)

This article has been dead for over six months. Start a new discussion instead.