***Welcome to ashrafedu.blogspot.com ***This website is maintained by ASHRAF***

posts

    Java Swing - difference between AWT and swing

    Swing in Java is a lightweight GUI toolkit which has a wide variety of widgets for building optimized window based applications. It is a part of the JFC( Java Foundation Classes). It is build on top of the AWT API and entirely written in java. It is platform independent unlike AWT and has lightweight components.

    The javax.swing package provides classes for java swing API such as JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.

    Swing component follows a Model-View-Controller architecture to fulfill the following criterias.

    • A single API is to be sufficient to support multiple look and feel.
    • API is to be model driven so that the highest level API is not required to have data.
    • API is to use the Java Bean model so that Builder Tools and IDE can provide better services to the developers for use.

    Swing API architecture follows loosely based MVC architecture in the following manner.

    • Model represents component's data.
    • View represents visual representation of the component's data.
    • Controller takes the input from the user on the view and reflects the changes in Component's data.
    • Swing component has Model as a separate element, while the View and Controller part are clubbed in the User Interface elements. Because of which, Swing has a pluggable look-and-feel architecture.

    Swing Features

    • Light Weight − Swing components are independent of native Operating System's API as Swing API controls are rendered mostly using pure JAVA code instead of underlying operating system calls.
    • Rich Controls − Swing provides a rich set of advanced controls like Tree, TabbedPane, slider, colorpicker, and table controls.
    • Highly Customizable − Swing controls can be customized in a very easy way as visual apperance is independent of internal representation.
    • Pluggable look-and-feel − SWING based GUI Application look and feel can be changed at run-time, based on available values.

    Difference between AWT and Swing

    Java AWT

    Java Swing

    AWT components are platform-dependent.

    Java swing components are platform-independent.

    AWT components are heavyweight.

    Swing components are lightweight.

    AWT doesn't support pluggable look and feel.

    Swing supports pluggable look and feel.

    AWT provides less components than Swing.

    Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc.

    AWT doesn't follows MVC(Model View Controller) where model represents data, view represents presentation and controller acts as an interface between model and view.

    Swing follows MVC.

    No comments:

    Post a Comment