tags:

views:

135

answers:

5

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?

+2  A: 

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.

Software Monkey
+3  A: 

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.

Luhar
A: 

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

dogbane
+1  A: 

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.

DaveJohnston
Swing looks pretty good on XP and Vista if you set the native look and feel. It looks native. Exactly.
Seun Osewa
Looking native doesn't necessarily mean looking good. I have developed GUIs in Swing, AWT and SWT over the years and of the 3 SWT is by far the best looking.
DaveJohnston
+1  A: 

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.

OscarRyz