Meaningless Drivel is fun!
The moose likes Swing / AWT / SWT and the fly likes Behind Swings. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Behind Swings." Watch "Behind Swings." New topic

Behind Swings.

L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Can anyone explain me how exactly Swings work. I.e. It uses java code to create the components.
where as the AWT uses Native code to do the same
what does this mean.
Please explain.

Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
in the beggining , a long long time ago when java was created, the people in sun decided they wont "reinvent the wheel" and decided to use the exsisting platform tools to create the GUI.
the java code would simply access the "button gui" for example in whatever platform it was running and create that button.
the result was that it worked perfectly BUT they had to reduce the gui (the graphics) to the lowest , most common graphics, in order to be compatible with all the platforms.
later, in the next versions, they decided to do everything themselves and they created their own components (widgets) using java code alone.
this allowed for far more complex graphics with many more cool things that will be identical on all platforms (unlike before when there were diffrences in the graphics because each platform draws buttons diffrently).
it is much better, nicer and cool but a little more slow than the native code.
the awt components are called heavier components because they rely on the native code and the swing ones are called light components.
the only rule is not mix the two.
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Thanks Roy.
But can you explain me more about the the way AWT code works. i.e. Where does it get native code for creating lets say button.
If I am not wrong then, in swings the Java code is going to take care of creating components and it does not use the native code.
waiting for your comments and reply.
Thanks again.
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
im not too sure of the specifics :roll:
but you can check the source code for the Button class for example in the src.jar file included with all JDK.
i guess , they just access the current platform they run in and use its componenets (like in windows, it uses the WIN32 API to create it).
sorry i cant provide more information, maybe someone else can.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
There is a Getting Started article at the
Swing Connection:
Hope this helps
I agree. Here's the link:
subject: Behind Swings.
It's not a secret anymore!