dcsimg
difference between AWT and Swing
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sireesha_p
Posted On:   Tuesday, August 16, 2005 06:14 AM


I have heard this most commmon question. what is the difference between AWT and Swing?
may i know it?

Re: difference between AWT and Swing

Posted By:   Anonymous  
Posted On:   Tuesday, September 27, 2005 03:38 AM

Here are some difference betn AWT and Swing.

1.AWT components are called HeavyWeight component and Swings are called ligth weight component because swing components sits on the top of AWT components and do the work.
2.swings components are made in purely java and they are platform independent whereas AWT compoents are platform dependent.
3.we can have different look and feel in Swing whereas this feature is not supported in AWT.
4.Swing has many advanced features like JTabel,Jtabbed pane
which is not available in awt..

Also.
Swing components are called "lightweight" because they do not require a
native OS object to implement their functionality. JDialog and JFrame are
heavyweight, because they do have a peer. So components like JButton,
JTextArea, etc., are lightweight because they do not have an OS peer.


With AWT, you have 21
"peers" (one for each control and one for the dialog itself). A "peer" is a
widget provided by the operating system, such as a button object or an entry
field object.

With Swing, you would have only one peer, the operating system's window
object. All of the buttons, entry fields, etc. are drawn by the Swing
package on the drawing surface provided by the window object. This is the
reason that Swing has more code. It has to draw the button or other control
and implement its behavior instead of relying on the host operating system
to perform those functions.

Several consequences result from this difference between AWT and Swing. AWT
is a thin layer of code on top of the OS, whereas Swing is much larger.
Swing also has very much richer functionality. Using AWT, you have to
implement a lot of things yourself, while Swing has them built in. For
GUI-intensive work, AWT feels very primitive to work with compared to Swing.
Because Swing implements GUI functionality itself rather than relying on the
host OS, it can offer a richer environment on all platforms Java runs on.
AWT is more limited in supplying the same functionality on all platforms
because not all platforms implement the same-looking controls in the same
ways.

Swing components are called "lightweight" because they do not require a
native OS object to implement their functionality. JDialog and JFrame are
heavyweight, because they do have a peer. So components like JButton,
JTextArea, etc., are lightweight because they do not have an OS peer.

Re: difference between AWT and Swing

Posted By:   ashok_kumar  
Posted On:   Tuesday, August 16, 2005 07:03 AM

It is very frequently asked question in all the places if you say you know java!! JFC(java foundation classes) offers two different frameworks for us to build GUI applications one is swing and another one is awt.

With the help of the awt classes if you try to build the gui application those GUI Control components doesn't have the neutral look and feel. Example if u construct a button with the help of awt package that button will look like a window button it u try to run it in windows platform..


If you run the same application in MAC OS the button will look like a MAC button, so all the component adhere to the
underlying platform components. Sometimes it refered as the "native look and feel".Because the awt package was built with native classes..(i Think so)..

But swing package is developed with java language(That's Why javax.swing).. All the swing components will have neutral look and feel over the platforms.. Since awt and swing shares the same event delegation model, as well same layout management policy..

Swing is not the replacement of awt it is the enhancement of awt.. which offers better look and feel over the platforms.

About | Sitemap | Contact