0% found this document useful (0 votes)
21 views2 pages

Java Unit V

Swing is a set of Java classes that provide more flexible GUI components than AWT, addressing its limitations such as heavyweight components and fixed look and feel. Built on AWT, Swing introduces lightweight components and a pluggable look and feel, allowing for consistent appearance across platforms and easy customization. The architecture of Swing is based on a modified MVC model, where the view and controller are combined into a UI delegate, enabling changes in appearance without affecting functionality.

Uploaded by

manohar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Java Unit V

Swing is a set of Java classes that provide more flexible GUI components than AWT, addressing its limitations such as heavyweight components and fixed look and feel. Built on AWT, Swing introduces lightweight components and a pluggable look and feel, allowing for consistent appearance across platforms and easy customization. The architecture of Swing is based on a modified MVC model, where the view and controller are combined into a UI delegate, enabling changes in appearance without affecting functionality.

Uploaded by

manohar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

The Origin of Swing

 Swing is a set of classes that provide more powerful and flexible GUI Components
than AWT(Abstract Window Toolkit).
 The AWT defines a basic set of controls, windows and dialog boxes that support a
usable, but limited graphical interface.
 It was a response to deficiencies present in AWT.
 One reason for limited nature of the AWT is that , it translates its various visual
components into their platform-specific equivalents i.e the look and feel of a
component is defined by the platform, not by java.
 Because AWT components use native code resourcess, they are referred as
heavyweight.
 Several problems of AWT are
 First, because of variations between OS, a component might look, or even ac
differently on different platform.
 Second, the look and feel of each component was fixed and could not be easily
changed.
 Third, the use of heavy weight components caused some frustrating restrictions like
heavy weight component is always rectangular and opaque.
 To overcome the limitations and restrictions of AWT,a better approach is needed and
the solution was Swing, which is introduced in 1997.

Swing is Built on the AWT

 Although Swing eliminates a number of limitations inherent in the AWT, swing does
not replace it.
 Instead, swing is built on the foundation of AWT. This is the reason why the AWT is
still a crucial part of java.
 Swing also uses the same event handling mechanism as the AWT.
 Therefore, a basic understanding of the AWT and of event handling is required to use
swing.

Two Key Features of swing

 Swing was created to address the limitations present in the AWT. It does this through
two key features
1) Lightweight components
2) Pluggable look and feel.
 Together, they provide elegant, yet easy –to-use solution to the problems of the AWT.
1) Swing components are LightWeight
o Swing components are lightweight, means that they are written entirely in java
and do not map directly to platform-specific peers.
o Because light weight components do not translate into native peers, the look and
feel of each component is determined by swing, not by underlying operating
system.
o i.e Each component will work in a consistent manner across all platforms.
2) Swing supports a pluggable look and feel
 Swing supports a pluggable look and feel(PLAF). Since swing follows MVC
architecture, it is possible to separate the look and feel of s component from the
logic of the component.s
 Separating out the look and feel provides a significant advantage
 It becomes possible to change the way that a component is rendered without
affecting any of its other aspects.s
 In other words, it is possible to “plug in” a new look and feel for any given
component without creating any side effects in the code that uses that
component.
The MVC Connection
 In general, a visual component is a composite of 3 distinct aspects.
o The way that the component looks when rendered on the screen.
o The way that the component reacts to the user.
o The state information associated with the component.
 MVC(Model-View-Controller) is an exceptionally effective component architecture.
 In MVC terminology
o Model, corresponds to the state information associated with the component. For
eg, in case of check box, the model contains a field that indicates if a box is
checked or unchecked.
o View, determines how the component is displayed on the screen, i.e represents
the current state of the Model. For eg., in case of checkbox, the view represents
a unchecked checkbox if current state of the model is unchecked.
o Controller, determines how the component reacts to the user. For eg., when the
user clicks a checkbox, the controller reacts by changing the model to reflect the
users choice. This then results in the view being updated.
 By separating a component into a Model, a View and a Controller, the specific
implementation of each can be changed without affecting the other two.
 Although the MVC architecture and the principles behind it are conceptually sound,
the high level of separation b/w the view and the controller is not beneficial for swing
components.
 Instead, swing uses a modified version of MVC that combines the view and controller
into a single logical entity called the UI delegate.
 Therefore swings approach is called either as Model-delegate architectute or the
separable model architecture.
 Swings pluggable look and feel is made possible by its Model-Delegate Architecture,
because the view(look) and controller(feel) are separate from the Model, the look and
feel can be changed without affecting how the component is used within a program.
Components and Containers

You might also like