Showing posts with label what is swing components. Show all posts
Showing posts with label what is swing components. Show all posts

Friday, 1 March 2019

swing components in java

Swing Components in java:

Swing components facilitate efficient graphical user interface(GUI) development. These components are a collection of lightweight visual components. swing components contain a replacement for the heavyweight AWT components as well as Complex user interface components such as trees and tables.




Swing components contain a pluggable look and feel. This allows all applications to run with the native look and feel on different platforms. PL&F allows the application to have the same behavior on various platforms. JFC contains operating systems neutral look and feel. swing components do not contain peers. 

Swing components allow mixing awt heavyweight and Sewing lightweight components in an application. The major difference between lightweight and the heavyweight component is that lightweight components can have transparent pixels while heavyweight components are always opaque. lightweight components can be nonregular while heavyweight components are always rectangular.

Swing components comprise a large percentage of the JFC release. The swing component toolkit consists of over 250 pure java classes and 75 interfaces contained in about 10 packages. They are used to build a lightweight user interface. Swing consists of user interface(UI) classes and non-user interface classes. The non-UI classes provide services and other operation for UI classes.


Swing features in Java:

MVC architecture :

The user can provide his own data model for a component by subclassing the model class or by implementing the appropriate interface. The Model-View-Controller architecture is used to consistently throughout the swing component set. The view and Controller parts of the architecture are combined in the component.

Nested Container:

The swing was designed to manage nested containers gracefully. The main heavyweight container(JWindow, JFrame etc.) as well as the major lightweight containers(JInternalFrame and JComponents) all delegate their operations to a JRootPane. This commonly produces a high degree of regularity in container nesting. In particular, since the fundamental component class(JComponent) contains a JRootPane, virtually any component can be nested within another.

Keystroke Handling:

A user can register interest in a particular combination of keystroke by creating a keystore object and registering it with the component. When the key combination is registered along with its association action, certain conditions have to be specified. These determine the time of initiation of the action.

Action objects:

Action interface object provides a single point of Control for the program. An example of this would be a toolbar icon and a menu item referencing the same action object. When action disabled, GUI items that reference it are automatically disabled.

Virtual desktop :

The JDesktopPane and JInternalFrame classes can be used to create a virtual desktop or multiple document interface. A JInternalFrame can be specified are cognizable, Expendables or closable, while JDesktopPane provides real estate for them to operate in.

Pluggable look and feel:

The user can select a look and feel and this can be plugged in . An interface made of Swing components can look like a win32 app,a motif app. it can use the new metal look and feel.

Wide variety of components:

Class names that start with J are components that are added to an application. For example JButton, Jlist,JPanel .



Difference between swing and AWT:

There are many differences between Java AWT and swing that are given below:

Swing
 AWT
Java swing components are platform independent
AWT components are platform dependent
Swing components do not need any native code to implement.
AWT  components can be implemented with the code
swing components are lightweight
 AWT components are  heavyweight
swing components support the pluggable look and feel
AWT does not support pluggable look and feel
Swing lets you specify which look and feel your programs GUI uses
 AWT components always have the look and feel of native platform
swing component provides a more powerful component such as a table, lists, scroll pane, color chooser, tabbed pane etc.
AWT  provides fewer components than swing.
 swing components don't have to be rectangular. For example, a button can be rounded
AWT components are always rectangular

GUI components:


Graphical user interface GUI  is a method of interacting with a computer through a metaphor direct manipulation of graphical images and widgets(windows widgets).A GUI(pronounced “gooey”) component is an object with which the user interaction via the keyboard or another form of input.

Common GUI Event types and listener interfaces:

There are many different types of events that can occur when the user interacts with a GUI. The information about any GUI event that occurs is stored in an object of a class that extends the AWT event. These event types are used with both AWT and swing components. Additional events types that are specific to swing GUI components are declared in the package javax.swing.event.

The three parts to the event handling mechanism are as follows:

Event source: The event source is the GUI component with which the user interacts.

Event object: The event object encapsulates information about the event that occurred, such as a reference to the event source and any event-specific information.

Event listener: An event listener is an object that is notified by the event source when an event occurs. The method of event listener receives an event object when the event listener is notified of the event.

The classes associated with swing components are:

  • JLabel class
  • JTextField
  • JTextArea
  • JButton
  • JOptionPane
  • JCheckBox
  • JCcomboBox
  • JSlider
  • JFrame
  • JList
  • JPanel
  • event handling
  • layout manager
  • graphics class