简体   繁体   中英

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

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?

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.

Applet是AWT,而JApplet是Swing,JApplet是Applet的扩展版本,因此它更新。

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.

Applet -> AWT

JApplet -> Swing + support for assistive technologies +

I suggest using JApplet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM