简体   繁体   中英

What's the difference between Java Swing & Java Applets

I've got a question today and would like to know which would be better to use in Java development. Which would be better to use: Java Swing OR Java Applet . I am new to Java development and have been confused between the two.

  • If you were creating a game which would be better to use.
  • Which is better to understand and uses less lines ect.
  • Which is light weight?

Any questions would be awesome!

Java Swing OR Java Applet

There is some confusion here.

AWT has Frame for desktop applications/ Applet for applets. Swing has JFrame for desktop applications/ JApplet for applets.

Other matters:

  1. AWT/Swing. Why AWT rather than Swing? See this answer on Swing extras over AWT for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see Mixing Heavyweight and Lightweight Components .

  2. Applet vs. application. Why code an applet? If it is due to spec. by teacher, please refer them to Why CS teachers should stop teaching Java applets .

Many of the components in javax.swing.* have made other still accessible JDK components obsolete, such as AWT. Swing is actually built on top of AWT, and is a large improvement in performance, features, and usage over AWT.

This tutorial on custom graphics with Swing may help: http://www.ntu.edu.sg/home/ehchua/programming/java/J4b_CustomGraphics.html

As for Java Applets , these are unrelated to Swing in terms of normal application development. Java Applets are small applications that can run in a web browser.

Swing is a set of platform independent UI tools (JButton, JScrollBar, etc.). It guarantees that your user interface design will look the same on different platforms. An applet is an app that runs inside a browser or other hosted environment. An applet can use Swing UI, but doesn't need to.

Personally, I wouldn't develop a game in either if it's graphics intensive. If you want lightweight, I would suggest using JavaScript in Chrome's V8. Check out Chrome's developer showcase. They're doing amazing things with Javascript these days.

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