Swing What is the difference between AWT and Swing? The biggest difference between the AWT components and Swing components is that the Swing components are implemented with absolutely no native code. They are platform independent. Swing components provide much more features than what the AWT components offer:
What are the heavyweight and lightweight components? The AWT control components provide their graphical representation by using native peer components. The peer will be responsible for the look and feel of that particular component. These controls are heavyweight. When the components are not supported by a native peer, they are lightweight components. The difference between lightweight and heavyweight components is z-order: the notion of depth or layering. When Swing components (and all other "lightweight" components) overlap with heavyweight components, the heavyweight component is always painted on top. The Pane Container Model Swing top-level containers include JFrame, JDialog, JWindow and JApplet. There is a JRootPane class under them to rpovide more facilities: a content pane, a layered pane, a glass pane and menu-bar. The following methods help you getthem respectively. Container getContentPane(); Component getGlassPane(); JLayeredPane getLayeredPane(); Components can not be added directly to a top-level container such as a JFrame. Instead, they should be added to a content pane that is itself contained by the JFrame. MVC architecture The model is responsible for maintaining all aspects of the component state. Instead the model will send out notifications or broadcasts (what we know as events). The view determines the visual representation of the component's model. The view is responsible for keeping its on-screen representation updated and may do so upon receiving indirect messages from the model, or direct messages from the controller. The controller is responsible for determining whether the component should react to any input events from input devices such as the keyboard or mouse. It determines what actions are performed when the component is used. |