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

5

12

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?

Garmaise answered 25/1, 2012 at 19:33 Comment(1)
I would use JApplet since it extends Applet. By using JApplet, you can do everything a JApplet can do plus anything an Applet can do.Molarity
C
18

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.

Cairo answered 25/1, 2012 at 19:38 Comment(1)
so how to decide when to use JApplet and Applet?Secede
J
4

Applet is AWT whereas JApplet is Swing, JApplet is the extended version of Applet, therefore it is more recent.

Judijudicable answered 25/1, 2012 at 19:38 Comment(0)
S
3

Use JApplet. Swing is better, and few people remember how to use AWT components.

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?

Probably not. Many examples are written that way in order to make them easy to compile and run. Code should be divided into separate classes according to the best design, and only the most trivial of code would be expressed in a single class.

Skerl answered 25/1, 2012 at 19:39 Comment(0)
B
3

Applet -> AWT

JApplet -> Swing + support for assistive technologies +

I suggest using JApplet

Bucky answered 25/1, 2012 at 19:41 Comment(0)
M
2

Here's what the API specification says Applet: http://docs.oracle.com/javase/6/docs/api/java/applet/Applet.html

JApplet (extends Applet) : http://docs.oracle.com/javase/6/docs/api/javax/swing/JApplet.html

Molarity answered 25/1, 2012 at 19:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.