Swing (Graphics Programming in java):

Swing is a part of JFC (Java Foundation Classes) that is used to create GUI application. It is built on the top of AWT and entirely written in java.

Advantage of Swing over AWT:

There are many advantages of Swing over AWT. They are as follows:
  • Swing components are Plateform independent.
  • It is lightweight.
  • It supports pluggable look and feel.
  • It has more powerful components like tables, lists, scroll panes, color chooser, tabbed pane etc.
  • It follows MVC (Model View Controller) architecture.

What is JFC ?

The Java Foundation Classes (JFC) are a set of GUI components which simplify the development of desktop applications.

Do You Know ?
  • How to display image on a button in swing?
  • How to change the component color by choosing a color from ColorChooser ?
  • How to display the digital watch in swing tutorial ?
  • How to create a notepad in swing?
  • How to create puzzle game and pic puzzle game in swing ?
  • How to create tic tac toe game in swing ?

Hierarchy of swing:

hierarchy of swing

Commonly used Methods of Component class:

1)public void add(Component c)
2)public void setSize(int width,int height)
3)public void setLayout(LayoutManager m)
4)public void setVisible(boolean)

Creating a Frame:

There are two ways to create a frame:
  • By creating the object of Frame class (association)
  • By extending Frame class (inheritance)

Simple example of Swing by Association:

public void setBounds(int xaxis, int yaxis, int width, int height); have been used in the above example that sets the position of the button.
simple example of swing

Simple example of Swing by inheritance:

Next TopicJButton Class