• Latest
  • Trending
How to Write Your First Java GUI Application 

How to Write Your First Java GUI Application 

February 22, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Friday, 17 July, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

How to Write Your First Java GUI Application 

Take your first steps in Java GUI programming and learn how to open a window.

by ITECHNEWS
February 22, 2022
in Data Science, Leading Stories
0 0
0
How to Write Your First Java GUI Application 

Java uses a set of features provided by JFC (Java Foundation Classes) to create graphical user interfaces (GUIs). JFCs are part of the Java platform and are therefore cross-platform.

These classes provide features such as pluggable look-and-feel, internationalization, and Swing GUI components.

YOU MAY ALSO LIKE

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

This tutorial concentrates on how to use Swing components to create your first Java GUI application.

Swing Components

Swing is a JFC package that contains lightweight GUI components. It has 18 public packages. Fortunately, most of your applications will only need a few of them. In particular, javax.swing and javax.swing.event (less often).

For your application to appear on-screen, all the GUI components need to be part of a containment hierarchy. A containment hierarchy is a tree of components whose root is a top-level container.

Swing has three top-level container classes:

JFrame, used to create the main window/frame 

JDialog, used to create dialog boxes 

JApplet, used to add Swing components to applets 

The focus of this tutorial will be how to use the JFrame top-level container. Each top-level container generally consists of a content pane and optionally, a menu bar.

The content pane is a space into which you can place visible components of a top-level container. A menu bar contains a list of items on your GUI.

Creating a Frame

A frame is the main window of your application and generally has a title and borders. To create a frame, use the JFrame container class:

The class has a constructor that allows you to define the title of your window. However, instantiating a frame alone is not enough to make your window appear on-screen.

You need to set the setVisible() method to true for your application to appear. With this minimal code, your application can now appear:

If you ran the code above, you most probably took at least a minute darting around your screen while looking for the application window. You most probably found a barely visible window at the edge of your computer screen.

Apart from this, you’ll notice that the program doesn’t stop running when you click the cancel button on your application window. You can notice this from your command line.

The window will close, but the program will continue running in the background. This is because the default behavior is to hide the frame on exit. More useful behavior might be to exit the program or shift control to another program.

To solve these two issues, you’ll need to use the setSize() and setDefaultCloseOperation() methods. See the code below:

In the example above, the window-closing event defined is EXIT_ON_CLOSE. This means that your program will exit the application when you close the frame. There are other window-closing events that you can use:

HIDE_ON_CLOSE: This is the default operation which hides the window on closing, but leaves it displayable. 

DO_NOTHING_ON_CLOSE: This will perform no action when the user requests to close the window. Instead, a registered WindowListener handles closing with its windowClosing() method. 

DISPOSE_ON_CLOSE: This hides the windows and also frees the resources the program had allocated to it. 

Your First Python GUI Application

Now that you’ve learned how to create your first Java GUI application, it’s time to explore how to do so in Python. Python offers you the simplicity of less code to create your application.

It’s worth your time to learn how to use Python’s Tkinter library to create your GUI applications.

Source: BY JEROME DAVIDSON
Tags: First Java GUI Application
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version