What is the difference between JApplet and Applet, and which should I use?

Bhaxy picture Bhaxy · Jan 25, 2012 · Viewed 21.5k times · Source

In my book (for my computer science course) they have source code snippets. We're talking about graphics programming and applets. I've noticed that in some cases he extends JApplet, while in others he uses Applet.

I was wondering what the differences were, and how they would affect the code?

Recently, I've been tasked with creating a graphical hangman game, wherein the user tries to guess the computer's word. Should I use a JApplet or Applet (we've mostly used JApplet, which is why I'm leaning towards that, but I could go either way).

Furthermore, I was wondering what the basic process should be in an applet, some people do have all their code in a single file that extends JApplet or just JFrame. Should I do that?

Answer

Tim Cooper picture Tim Cooper · Jan 25, 2012

From the documentation for JApplet:

An extended version of java.applet.Applet that adds support for the JFC/Swing component architecture

If you're looking to use Swing components inside of your applet, JApplet would give you that functionality. Swing has superseded the original AWT, so it would still be a good idea to use JApplet in lieu of Applet, simply for keeping up with the current libraries.