What's the difference between Java Swing & Java Applets - java

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:
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.
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.

Related

SWT and AWT, what is the difference?

I understand that this question is rather general and kind of a holy war. Could you explain to me why SWT is successful when AWT is not, while these two frameworks use the same idea of native ui controls. What makes SWT different comparing to AWT? Just few words if possible.
Thank you.
AWT is the original cross-platform, native-peer based GUI widget set. It drew a lot of complaints for not being perfectly consistent across platforms. Sun built the Swing widget set to answer those concerns, building it with pure Java (no native peers), but people complained that it was slow and ugly.
IBM built SWT as a native-peer based competitor to Swing. It succeeded because it looks good, performs well and is pretty consistent across platforms. It cemented it's position by getting used by many popular applications, Eclipse and Vuze being the most obvious.
SWT provides a lot richer set of native heavyweight widgets than AWT - a proper comparison would be SWT vs AWT/Swing. Due to that, SWT looks more native than AWT/Swing. While this could be considered a success, it can also be a drawback, depending on what you need to implement. In case of SWT you are using only heavyweight native widgets with all possible OS limitations. With AWT/Swing you have the option to mix lightweight Swing (pure Java) widgets with native AWT widgets for better performance.

How is google's alternative to awt and swing in Java?

I use swing now for my GUIs in Java, and I was wondering about the quality of gwt. Are there compatibility issues with some things (I have a hard time with serialization sometimes when using swing, as an example), is the interface intuitive? How is the performance?
Swing and AWT are for desktop applications. GWT is for web applications. They're not comparable at all.
GWT is not just a GUI toolkit, it is a complete framework including a Java to JavaScript compiler, for writing Java code to be compiled into JavaScript and run by the browser. It includes support for serialization and other nice things, but it doesn't support the entire Java language/API. (No reflection for example).
Java applets are really just Java applications running within the browser. Applets don't really integrate with the HTML document model, and (Applet's) don't describe their GUI using html.
For doing GUI development: GWT does all its layout in the HTML DOM modul(Like you would if you wrote the JavaScript yourself) so to do layout you need to understand how HTML and CSS work.
Using GWT for GUIs are very different from using Swing/AWT exactly because you need to describe the GUI using HTML/CSS elements.

Build Java UI to run on all platforms

I am really confused over what to use. Options I see are awt, Swing and swt.
My question is which should be best for Desktop Java app on all platforms( Mac,Windows and Linux )with minimum platform dependent code ?
AWT is obsolete, though some of its classes and design form the underpinnings of the Swing API.
Here is my take on the differentiators between creating applications in Swing and SWT:
Swing
+ Forms part of the standard Java-SE platform, so fewer distribution headaches
+ You can create a consistent look and feel across platforms
+ Controls are lightweight, so creating your own is relatively easy
- If you need Swing applications to look like native applications, there may be a lot of work in it; Swing can be styled with a platform look'n'feel, but the results aren't always close enough for everyone's satisfaction
SWT
+ Easy to create simple applications which use native widgets
- Manual resource management
- You need to distribute platform-specific libraries
- You face the lowest-common-denominator problem - not all widgets are available on all platforms, so some will be custom to SWT anyway
Although I've put a lot more minuses against SWT, I wouldn't discount it. Which technology you pick will depend on your project requirements. Picking the library is only the beginning when it comes to UI development.
Swing is the easy, low-maintenance option and I'd agree with the other posters that this is probably the best fit for what you want.
Swing.
AWT is old and too low-level, SWT has native components, and doesn't ship with the JRE (it's a third-party library). Swing is high-level (-ish), and pure-java.
I would go with Swing as the best choice using what's packaged with Java. However, even Swing can make you jump through all the same hoops every time, so I would recommend looking into one of various frameworks that build on top of it and handle most of the boilerplate work of building an app.
There's a JSR for a Swing Application Framework which I have used when it was still in active development, but it's currently frozen. Their project page recommends a fork of that project, and another one called GUTS which uses Google Guice as its dependency injection. Netbeans also has Netbeans Platform.
I know the scope of these frameworks goes outside the realms of "UI", but they handle things like data-binding between your model and your UI which Swing does not do.

If Swing has more features to design a form. Then what is the use of AWT in java?

In java, Swing has more features than the AWT components.
For example,
In AWT,
TextArea ta;
Button btn;
But its same in Swing as,
JTextArea ta;
JButton btn;
But swing component has good in look.
Then what's the need of AWT. Is there any useful feature?
Swing and AWT both provide user interface components, however Swing is built on top of AWT. It provides richer tools like icons, tool tips, etc. which are not available in AWT. Also, Swing is meant to be portable, while AWT (in theory) will match more of the system's look and feel.
Most IDEs that give you GUI building features (NetBeans, etc) will do so using Swing components. AWT is useful since it provides the foundation on which Swing is built.
More details here.
AWT is useful if you want truer O/S fidelity and can accept a lowest-common-denominator for widget support.
It's also immensely useful for building your own light-weight GUI on (suppose, for a game engine). For example, we needed a GUI system which would run on handhelds in JME PP 1.0 as well as desktops and thin clients, where we needed only a few basic components, but really minimal overhead, so I built a GUI toolkit which runs within an AWT Panel. It worked out really well.
AWT was the GUI package available in Java, then along came Swing, which was built on top of AWT in an attempt to make things look nicer and consistent across platforms. The problem is, they both look terrible. I am stuck with AWT in my project unfortunately, because it is a Windows Mobile project and our VM only supports AWT.
If you want a java GUI that actually looks nice (well nicer than Swing or AWT) then you want to check out SWT from IBM.
AWT was the first try on UI for Java, later Swing provided a better alternative because they use "light" components ( the component draw the UI them selves instead of relaying on native code ) and those light components were way lot flexible and maintainable then AWT.
AWT still has it's place as the underlying "technology" that interface Swing and the OS ( JComponent inherits java.awt.Container after all) , so, its place in the low level of UI. For instance, things like translucency, shapes etc. are placed in AWT package and they are used by Swing components.
New platform UI features will be added to Java in the following releases and many of them will be added to the java.awt. package.
AWT is still commonly used for applets! Most web browsers support AWT classes, so AWT applets can run without the Java plugin. Swing applets, however, require the Java plugin. Swing is not supported by older JVMs.
AWT is slighter faster because it uses native OS peer components, whereas Swing draws all its own components at the bit level. Swing components may not look and behave exactly like their native counterparts. AWT applications, however, will look like native apps and so will look different on different platforms. In contrast, Swing apps will look the same on all platforms (although this can be changed with code).

Java's AWT or Swing for GUI construction?

I need to compose a fairly simple GUI for a server monitoring process. It will have a few tabs which lead to a log tailing, counts of resources, and a start and top control. Nothing fancy here. Which Java framework, AWT or Swing, makes more sense for something this simple.
Swing is the way to go. It's a cleaner programming interface, and looks better.
Use Swing or SWT, since AWT has no tabs built in.
Starting with Java 6 Update 10, Swing got an entirely new look and feel, the 'Nimbus Look and Feel'. It looks great and is really fast because it uses vector graphics.
Swing is your best choice if you're stuck choosing between Swing and AWT.
If you have the flexibility, I would at least consider SWT. It's faster, matches the platform look and feel, and seems to have fewer porting hurdles and regression problems from release to release. There is a small hurdle in setting up your first project (getting the right jars and such), but other than that, it's no more difficult to work in.
AWT was the first Java GUI framework, it had a lot of flaws and was abandoned in favor of Swing. The main reason it is still in the JDK is for backwards compatibility and because some classes are re-used by Swing.
The future however (even for the desktop) could be JavaFX.
if you are planning to move your gui onto multiple platforms, then go with AWT. Otherwise, Swing gives you a much broader set of components to work with.
If you are looking for a better looking GUI, you can have a look at substance look and feel package in this address: https://substance.dev.java.net/see.html

Categories

Resources