VOOZH about

URL: https://www.geeksforgeeks.org/java/creating-frames-using-swings-java/

⇱ Creating Frames using Swings in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Creating Frames using Swings in Java

Last Updated : 17 Feb, 2022

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:

  1. By creating the object of Frame class (association)
  2. By extending Frame class (inheritance)
  3. Create a frame using Swing inside main()

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 drawing

Note: 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: 
 

πŸ‘ Untitled drawing (1)

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. 

Comment
Article Tags:
Article Tags: