![]() |
VOOZH | about |
Swing is a part of JFC (Java Foundation Classes). Building Graphical User Interface in Java requires the use of Swings. Swing Framework contains a large set of components that allow a high level of customization and provide rich functionalities and is used to create window-based applications.
Java swing components are lightweight, platform-independent, provide powerful components like tables, scroll panels, buttons, lists, color chooser, etc. In this article, we'll see how to make frames using Swings in Java. Ways to create a frame:
Methods:
Way 1: By creating the object of Frame class (association)
In this, we will see how to create a JFrame window by instantiating the JFrame class.
Example:
Way 2: By extending Frame class (inheritance)
In this example, we will be inheriting JFrame class to create JFrame window and hence it wonβt be required to create an instance of JFrame class explicitly.
Example:
Output:
π Untitled drawing (2)
Note : You won't be able to run this code on an online compiler, so I have added an image to show you the output.
Way 3: Create a frame using Swing inside main()
Example 1:
Output:
π Untitled drawingNote: You won't be able to run this code on the online compiler, so I have added an image to show you the output.
Example 2:
Output:
Note : You won't be able to run this code on an online compiler, so I have added an image to show you the output.