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 componenets 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.|
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 by inheritance: