Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AWT and Swing!!!  RSS feed

 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi folks,
i read that swing is a lightweight components and used so that application designed with is platform independent as it does not rely rendering components on a particular OS. But I am confused to see examples which still use "import java.awt.* and import java.awt.event.*"together with javax.swing.*;. If it imports all these awt packages, isn't it still relying on OS? please explain me how can we reason that an application using such combination of packages does not rely on OS?
thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Namaste Sathi
Well, someone will correct me if I am wrong, however, I believe that the AWT components that are still used in conjunction with SWING are not GUI elements for the most part.
For example, to perform an action on the click of a JButton, you create a new java.awt.event.ActionListener and then you will also use a java.awt.event.ActionEvent.
There are a lot of SWING GUI components that inheret from AWT Components. But most of the inheretance is not directly related to actually DRAWING the components. SWING does all the drawing (indirectly) for you. But methods to add events, listeners, and the like can all come from AWT. So for example, a java.awt.Button has a addActionListener() method. So why would Sun want to re-code this method for a JButton when it does the exact same thing? So JButton might inheret/extend Button which inherets/extends java.awt.AbstractButton. I am not too sure about the exact inheretance as I am not looking at the API. But this at least give you an idea.
On an aside - Keeping questions relating the same information in the same thread is a good idea. So instead of starting a new thread for every question, you can just respond to your own original thread. This not only helps us Bar-keeps help you better, but it also allows for other people trying to learn to better follow the logic of your questions and answers.
[ August 26, 2003: Message edited by: Gregg Bolinger ]
 
Charles Hasegawa
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both AWT and Swing rely on the OS. The JVM that is running on the system handles the translation - that is how the we say that the Java app is not OS dependent. You write code to an API spec, as long as the JVM is at the same version or above, your code "should" run the same.
I say "should", because native widgets are of course vastly different from OS to OS. One of the most obvious example is the JFileChooser. This dialog looks very different on Windows and Solaris for example. This is because the native save dialogs provide different amount of functionality, even though they do basically the same thing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!