InternalFrameListenerDemo.java Source code

Java tutorial

Introduction

Here is the source code for InternalFrameListenerDemo.java

Source

import java.awt.BorderLayout;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

public class InternalFrameListenerDemo {
    public static void main(final String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JDesktopPane desktop = new JDesktopPane();
        JInternalFrame internalFrame = new JInternalFrame("Can Do All", true, true, true, true);

        desktop.add(internalFrame);

        internalFrame.setBounds(25, 25, 200, 100);

        JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
        internalFrame.add(label, BorderLayout.CENTER);

        internalFrame.setVisible(true);

        internalFrame.addInternalFrameListener(new InternalFrameListener() {

            public void internalFrameClosing(InternalFrameEvent e) {
                displayMessage("Internal frame closing", e);
            }

            public void internalFrameClosed(InternalFrameEvent e) {
                displayMessage("Internal frame closed", e);
            }

            public void internalFrameOpened(InternalFrameEvent e) {
                displayMessage("Internal frame opened", e);
            }

            public void internalFrameIconified(InternalFrameEvent e) {
                displayMessage("Internal frame iconified", e);
            }

            public void internalFrameDeiconified(InternalFrameEvent e) {
                displayMessage("Internal frame deiconified", e);
            }

            public void internalFrameActivated(InternalFrameEvent e) {
                displayMessage("Internal frame activated", e);
            }

            public void internalFrameDeactivated(InternalFrameEvent e) {
                displayMessage("Internal frame deactivated", e);
            }

            void displayMessage(String prefix, InternalFrameEvent e) {
                System.out.println(prefix + ": " + e.getSource());
            }

        });

        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);

        frame.add(desktop, BorderLayout.CENTER);
        frame.setSize(500, 300);
        frame.setVisible(true);
    }
}