javax.swing.InternalFrameListener - Internal Frame Listener Interface

This section provides a tutorial example on how to use javax.swing.JInternalFameListener interface that allows implementing classes to handle internal frame events.

The following program shows you how to create internal frame listeners:

 * Copyright (c) 1997-2018 All Rights Reserved.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class JInternalFrameListenerTest 
   implements InternalFrameListener, ActionListener {
   JFrame myFrame = null;
   int count = 0;
   public static void main(String[] a) {
      (new JInternalFrameListenerTest()).test();
   private void test() {
      myFrame = new JFrame("Internal Frame Listener Test");
      myFrame.setContentPane(new JDesktopPane());
      JMenuBar myMenuBar = new JMenuBar();
      JMenu myMenu = new JMenu("Frame");
      JMenuItem myMenuItem = new JMenuItem("New");
   public void actionPerformed(ActionEvent e) {
      JInternalFrame f = new JInternalFrame("Frame "+count);
   public void internalFrameActivated(InternalFrameEvent e) {
      System.out.println("Internal frame activated");
   public void internalFrameClosed(InternalFrameEvent e) {
      System.out.println("Internal frame closed");
   public void internalFrameClosing(InternalFrameEvent e) {
      System.out.println("Internal frame closing");
   public void internalFrameDeactivated(InternalFrameEvent e) {
      System.out.println("Internal frame deactivated");
   public void internalFrameDeiconified(InternalFrameEvent e) {
      System.out.println("Internal frame deiconified");
   public void internalFrameIconified(InternalFrameEvent e) {
      System.out.println("Internal frame iconified");
   public void internalFrameOpened(InternalFrameEvent e) {
      System.out.println("Internal frame opened");

Run this program, you will see a blank frame with one menu called "Frame". If you:

you will see the following messages generated from the internal frame listener methods.

Action performed              - Clicked "New" menu item
Internal frame opened
Action performed              - Clicked "New" menu item
Internal frame opened
Internal frame closing        - Clicked the close icon
Internal frame closed
Internal frame activated      - Clicked the maximize icon
Internal frame deactivated    - Clicked the minimize icon
Internal frame iconified
Internal frame activated      - Clicked the minimized image
Internal frame deiconified

At the end of the test, the main frame will look like this:

Internal Frame Listener
Internal Frame Listener

Table of Contents

 About This Book

 JDK (Java Development Kit)

 Introduction of Java Swing Package

 Graphics Environment of the Local System

 JFrame - Main Frame Class

 JLabel - Swing Label Class

 JButton - Swing Button Class

 JCheckBox - Swing Check Box Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 JComboBox - Swing Combo Box Class

 Menu Bar, Menus, Menu Items and Listeners

Creating Internal Frames inside the Main Frame

 javax.swing.JInternalFame - Internal Frame Class - Internal Frame Class Test

javax.swing.InternalFrameListener - Internal Frame Listener Interface

 Layout of Components in a Container

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker

 AWT (Abstract Windows Toolkit)

 Integration with Desktop System

 Archived Tutorials


 Full Version in PDF/EPUB