Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Java Tutorial
  • Java Spring
  • Spring Interview Questions
  • Java SpringBoot
  • Spring Boot Interview Questions
  • Spring MVC
  • Spring MVC Interview Questions
  • Java Hibernate
  • Hibernate Interview Questions
  • Advance Java Projects
  • Java Interview Questions
Open In App
Next Article:
Java AWT Tutorial
Next article icon

Java AWT Tutorial

Last Updated : 02 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Java AWT or Abstract Window Toolkit is an API used for developing GUI(Graphic User Interfaces) or Window-Based Applications in Java. Java AWT is part of the Java Foundation Classes (JFC) that provides a way to build platform-independent graphical applications.

In this AWT tutorial, you will learn the basics of the AWT, including how to create windows, buttons, labels, and text fields. We will also learn how to add event listeners to components so that they can respond to user input.

By the end of this tutorial, you will have a good understanding of the AWT and be able to create simple GUIs in Java.

Java AWT Basics

Java AWT (Abstract Window Toolkit) is an API used to create Graphical User Interface (GUI) or Windows-based Java programs and Java AWT components are platform-dependent, which means they are shown in accordance with the operating system's view. AWT is heavyweight, which means that its components consume resources from the underlying operating system (OS). The java.awt package contains AWT API classes such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List, and so on.

Points about Java AWT components

i. Components of AWT are heavy and platform dependent
ii. AWT has less control as the result can differ because of components are platform dependent.

Why AWT is Platform Independent?

The Java AWT utilizes the native platform subroutine to create API components such as TextField, CheckBox, and buttons. This results in a different visual format for these components on different platforms such as Windows, MAC OS, and Unix. The reason for this is that each platform has a distinct view of its native components. AWT directly calls this native subroutine to create the components, resulting in an AWT application resembling a Windows application on Windows OS, and a Mac application on the MAC OS. In simpler terms, the AWT application's appearance adapts to the platform it is running on.

Understanding how to use BeanFactory is vital for optimizing your application's performance. To delve deeper into Java programming, the Java Backend course offers a comprehensive look at various Java concepts and their applications.

AWT is platform independent even after the AWT components are platform dependent because of the points mentioned below:

1. JVM (Java Virtual Machine):

As Java Virtual Machine is platform dependent

2. Abstract APIs:

AWT provides an abstract layer for GUI. Java applications interact with AWT through Abstract API which are platform independent. Abstract API allows Java to isolate platform-specific details, making code portable across different systems.

3. Platform-Independent Libraries:

The Libraries of AWT are written in Java which they are totally platform-independent. Because of this, it ensures that AWT functionality remains consistent across different environments.

Java AWT Hierarchy

Java-AWT-Tutorial-Large

  • Components: AWT provides various components such as buttons, labels, text fields, checkboxes, etc used for creating GUI elements for Java Applications.
  • Containers: AWT provides containers like panels, frames, and dialogues to organize and group components in the Application.
  • Layout Managers: Layout Managers are responsible for arranging data in the containers some of the layout managers are BorderLayout, FlowLayout, etc.
  • Event Handling: AWT allows the user to handle the events like mouse clicks, key presses, etc. using event listeners and adapters.
  • Graphics and Drawing: It is the feature of AWT that helps to draw shapes, insert images and write text in the components of a Java Application.

Note: Container can be added inside another container as it is type of component.

Types of Containers in Java AWT

There are four types of containers in Java AWT:

  1. Window: Window is a top-level container that represents a graphical window or dialog box. The Window class extends the Container class, which means it can contain other components, such as buttons, labels, and text fields.
  2. Panel: Panel is a container class in Java. It is a lightweight container that can be used for grouping other components together within a window or a frame.
  3. Frame: The Frame is the container that contains the title bar and border and can have menu bars.
  4. Dialog: A dialog box is a temporary window an application creates to retrieve user input.

Java AWT Tutorial for Beginner & Experienced

Learn the basics of the Abstract Window Toolkit (AWT) in Java, for both beginners and experienced developers.

  • Java AWT Label
  • Java AWT Button
  • Java AWT TextField
  • Java AWT Checkbox
  • Java AWT CheckboxGroup
  • Java AWT Choice
  • Java AWT List
  • Java AWT Canvas
  • AWT Scrollbar
  • Java AWT MenuItem & Menu
  • Java AWT PopupMenu
  • Java AWT Panel
  • Java AWT Toolkit

1. Java AWT Label

Syntax of AWT Label

public class Label extends Component implements Accessible  

AWT Label Class Constructors

There are three types of Java AWT Label Class

1. Label():
Creates Empty Label.

2. Label(String str):
Constructs a Label with str as its name.

3. Label(String str, int x):
Constructs a label with the specified string and x as the specified alignment

2. Java AWT Button

AWT Button is a control component with a label that generates an event when clicked on. Button Class is used for creating a labeled button that is platform-independent.

Syntax of AWT Button

public class Button extends Component implements Accessible  

Java AWT Button Class Constructors

There are two types of Button class constructors as mentioned below:

1. Button( ):
Creates a Button with no label i.e. showing an empty box as a button.

2. Button(String str): 
Creates a Button with String str as a label. For example if str="Click Here" button with show click here as the value.

3. Java AWT TextField

Syntax of AWT TextField:

public class TextField extends TextComponent 

TextField Class constructors

There are TextField class constructors are mentioned below:

1. TextField():
Constructs a TextField component.

2. TextField(String text):
Constructs a new text field initialized with the given string str to be displayed.

3. TextField(int col):
Creates a new text field(empty) with the given number of columns (col).

4. TextField(String str, int columns):
Creates a new text field(with String str in the display) with the given number of columns (col).

4. Java AWT Checkbox

Syntax of AWT Checkbox:

public class Checkbox extends Component implements ItemSelectable, Accessible  

Checkbox Class Constructors

There are certain constructors in the AWT Checkbox class as mentioned below:

1. Checkbox():
Creates a checkbox with no label.

2. Checkbox(String str):
Creates a checkbox with a str label.

3. Checkbox(String str, boolean state, CheckboxGroup group):
Creates a checkbox with the str label, and sets the state in the mentioned group.

5. Java AWT CheckboxGroup

CheckboxGroup Class is used to group together a set of Checkbox.

Syntax of AWT CheckboxGroup:

public class CheckboxGroup extends Object implements Serializable  

Note: CheckboxGroup enables the use of radio buttons in AWT.

6. Java AWT Choice

The object of the Choice class is used to show a popup menu of choices.

Syntax of AWT Choice:

public class Choice extends Component implements ItemSelectable, Accessible 

AWT Choice Class constructor

Choice(): It creates a new choice menu.

7. Java AWT List

The object of the AWT List class represents a list of text items.

Syntax of Java AWT List:

public class List extends Component implements ItemSelectable, Accessible 

AWT List Class Constructors

The List of class constructors is defined below:

1. List():
Creates a new list.

2. List(int row):
Creates lists for a given number of rows(row).

3. List(int row, Boolean Mode)
Ceates new list initialized that displays the given number of rows.

8. Java AWT Canvas

Syntax of AWT Canvas:

public class Canvas extends Component implements Accessible  

Canvas Class Constructors

1. Canvas():
Creates new Canvas.

2. Canvas(GraphicConfiguration config):
It creates a new Canvas with the given Graphic configuration.

9. AWT Scrollbar

Syntax of AWT Scrollbar:

public class Scrollbar extends Component implements Adjustable, Accessible 

Java AWT Scrollbar Class Constructors

There are three constructor classes in Java mentioned below:

1. Scrollbar():
   It Creates a new vertical Scrollbar in the Application.

2. Scrollbar(int orientation):
   Creates a new vertical Scrollbar with the given orientation.

3. Scrollbar(int orientation, int value, int visible, int mini, int maxi):
    Creates a new scrollbar with the orientation mentioned with value as the default value and [mini, maxi] as the lower and higher limit.

10. Java AWT MenuItem & Menu

MenuItem class adds a simple labeled menu item on the menu. The MenuItem class allows you to create individual items that can be added to menus. And Menu is a component used to create a dropdown menu that can contain a list of MenuItem components.

 Syntax of Java AWT MenuItem

public class MenuItem extends MenuComponent implements Accessible  

Syntax of Java AWT Menu

public class Menu extends MenuItem implements MenuContainer, Accessible  

11. Java AWT PopupMenu

Java AWT PopupMenu is a component that is used for dynamically popping up a menu that appears when the user right-clicks or performs any other action on a component.

Syntax of AWT PopupMenu

public class PopupMenu extends Menu implements MenuContainer, Accessible  

12. Java AWT Panel

Java AWT Panel is a container class used to hold and organize graphical components in a Java Application.

Syntax of Java AWT Panel:

public class Panel extends Container implements Accessible  

13. Java AWT Toolkit

Java AWT Toolkit class provides us with a platform-independent way to access various system resources and functionalities. Subclasses of Toolkit are used to bind various components.

Syntax of Java AWT Toolkit

public abstract class Toolkit extends Object  

Event Handling Components - Java AWT

Here are some of the event handling components in Java:

  • Java ActionListener
  • Java MouseListener
  • Java MouseMotionListener
  • Java ItemListener
  • Java KeyListener
  • Java WindowListener
  • Close AWT Window

1. Java ActionListener

Java ActionListner is a interface which responds to the actions performed by the components like buttons, menu items ,etc.

Syntax of Java ActionListener:

public class ActionListenerExample Implements ActionListener  

There is only methods associated with ActionListner class that is actionPerformed().

Syntax of actionPerformed() method:

public abstract void actionPerformed(ActionEvent e);  

2. Java MouseListener

Java MouseListner is a interface that responds to the actions performed by mouse events generated by the user. Example: mouse clicks , mouse movements, etc.

There are 5 Methods associated with MouseListner:

1. mouseClicked(MouseEvent e):
Responds to mouse buttons when clicked on a component in the Application.

2. mousePressed(MouseEvent e):
Responds to mouse button is Pressed on a component in the Application.

3. mouseReleased(MouseEvent e):
Responds to Mouse button released after being pressed over a component in the Application.

4. mouseEntered(MouseEvent e):
Responds to the situation when a Mouse cursor enters the bounds of a component in an Application.

5. mouseExited(MouseEvent e):
Responds to the situation when a Mouse cursor exits a component's bounds.

3. Java MouseMotionListener

Java MouseMotionListner is a interface which is notified when mouse is moved or dragged.

It contains two Methods mentioned below:

1. mouseDragged(MouseEvent e):
Responds when the mouse is dragged with mouse button clicked over a component in Application.

2. mouseMoved(MouseEvent e):
Responds when the mouse is moved over a component in Application.

4. Java ItemListener

Java ItemListner is an interface which handles events related to item selection and deselection those that occur with checkboxes, radio buttons, etc. There is only one Method associated with ItemListner that is itemStateChanged(). This method provides information about the event, i.e. source of the event and the changed state.

Syntax of itemStateChanged() method:

itemStateChanged(ItemEvent e)

5. Java KeyListener

Java KeyListner is an interface in Java notified whenever you change the state of key or can be said for key related events.

Syntax of KeyListener:

public interface KeyListener extends EventListener 

There are three methods associated with KeyListner as mentioned below:

1. keyPressed (KeyEvent e):
Responds to the event when key is pressed.

2. keyReleased (KeyEvent e):
Responds to the event when the key is released.

3. keyTyped (KeyEvent e):
Responds to the key has been typed.

6. Java WindowListener

Java WindowListener is a interface used for handling events related to window actions. Events like opening , closing, minimizing, etc are handled using WindowListener.

Syntax of WindowListener

public interface WindowListener extends EventListener 

There are seven methods associated with WindowListener as mentioned below:

1. windowActivated (WindowEvent e):
Responds when window is first opened

2. windowClosed (WindowEvent e):
Responds when the user attempts to close the window

3. windowClosing (WindowEvent e):
Responds after a window has been closed

4. windowDeactivated (WindowEvent e):
Responds when a window is minimized

5. windowDeiconified (WindowEvent e):
Responds when a window is restored from a minimized state

6. windowIconified (WindowEvent e):
Responds when a window is activated

7. windowOpened (WindowEvent e):
Responds when a window loses focus

7. Java Adapter classes

Java adapter classes provide the default implementation of listener interfaces.

8. Close AWT Window

At the end we will need to Close AWT Window, So to perform this task we will use dispose() method. This method releases the resources associated with the window and also removes it from the screen.

Java AWT Examples

Here are some Java AWT examples:

  • Hello World in Java AWT
  • Java AWT Program to create Button

1. Hello World in Java AWT

Hello, World is was the first step in learning Java. So, let us program our first Program in Java AWT as Hello World using Labels and Frames.

Below is the implementation of the above method:

Java
// Java AWT Program for Hello World
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

// Driver Class
public class AWT_Example {
    // main function
    public static void main(String[] args)
    {
        // Declaring a Frame and Label
        Frame frame = new Frame("Basic Program");
        Label label = new Label("Hello World!");

        // Aligning the label to CENTER
        label.setAlignment(Label.CENTER);

        // Adding Label and Setting
        // the Size of the Frame
        frame.add(label);
        frame.setSize(300, 300);

        // Making the Frame visible
        frame.setVisible(true);

        // Using WindowListener for closing the window
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
    }
}

Running:

javac AWT_Example.java
java AWT_Example

Output:

Java AWT Hello World

2. Java AWT Program to create Button

Below is the implementation of the Java AWT Program to create a Button:

Java
// Java AWT Program for Button
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

// Driver Class
public class Button_Example {
    // main function
    public static void main(String[] args)
    {
        // Creating instance of frame with the label
        Frame frame = new Frame("Example 2");

        // Creating instance of button with label
        Button button = new Button("Click Here");

        // Setting the position for the button in frame
        button.setBounds(80, 100, 64, 30);

        // Adding button to the frame
        frame.add(button);

        // setting size, layout and visibility of frame
        frame.setSize(300, 300);
        frame.setLayout(null);
        frame.setVisible(true);

        // Using WindowListener for closing the window
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
    }
}

Running:

javac Button_Example.java
java Button_Example

Output:

Java AWT Button Output


Next Article
Java AWT Tutorial
author
kartik
Improve
Article Tags :
  • Java
  • Advance Java
  • Java-AWT
  • Tutorials
Practice Tags :
  • Java

Similar Reads

    Java Tutorial
    Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s
    10 min read
    Maven Tutorial
    Maven is a powerful project management and build automation tool, widely used by Java developers. It uses a Project Object Model (POM) to centralize and handle a project's build process, reporting, and documentation efficiently. Unlike other tools like ANT, Maven offers more advanced features, makin
    8 min read
    Java 8 Features - Complete Tutorial
    Java 8 is the most awaited release of the Java programming language development because, in the entire history of Java, it has never released that many major features. It consists of major features of Java. It is a new version of Java and was released by Oracle on 18 March 2014. Java provided suppor
    9 min read
    Java Networking
    When computing devices such as laptops, desktops, servers, smartphones, and tablets and an eternally-expanding arrangement of IoT gadgets such as cameras, door locks, doorbells, refrigerators, audio/visual systems, thermostats, and various sensors are sharing information and data with each other is
    15+ min read
    Java Cheat Sheet
    Java is a programming language and platform that has been widely used since its development by James Gosling in 1991. It follows the Object-oriented Programming concept and can run programs written on any OS platform. Java is a high-level, object-oriented, secure, robust, platform-independent, multi
    15+ min read
    Network Input in Java
    In Java, Network Input is all about sending and getting data over a network. It's about making links, getting data from input sources, and dealing with the information we get. Java offers strong tools, like input streams and sockets. These help with these operations so communication between devices
    2 min read
    Java Programming Basics
    Java is one of the most popular and widely used programming language and platform. A platform is an environment that helps to develop and run programs written in any programming language. Java is fast, reliable and secure. From desktop to web applications, scientific supercomputers to gaming console
    4 min read
    Java Syntax
    Java is an object-oriented programming language that is known for its simplicity, portability, and robustness. The syntax of Java programming language is very closely aligned with C and C++, which makes it easier to understand. Java Syntax refers to a set of rules that define how Java programs are w
    6 min read
    How to Run Java Program?
    Java is a popular, high-level, object-oriented programming language that was developed by James Gosling and his team at Sun Microsystems (now owned by Oracle Corporation) in the mid-1990s. It is widely used for developing various kinds of software, including web applications, desktop applications, m
    2 min read
    Java Hello World Program
    Java is one of the most popular and widely used programming languages and platforms. In this article, we will learn how to write a simple Java Program. This article will guide you on how to write, compile, and run your first Java program. With the help of Java, we can develop web and mobile applicat
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences