Reports all internal frame events that occur on one internal frame : InternalFrameListener « Swing Event « Java Tutorial






Reports all internal frame events that occur on one internal frame
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);
  }
}








15.19.InternalFrameListener
15.19.1.InternalFrameEvent Event Subtypes
15.19.2.Listening to InternalFrameListenerListening to InternalFrameListener
15.19.3.Reports all internal frame events that occur on one internal frameReports all internal frame events that occur on one internal frame
15.19.4.InternalFrameListener and InternalFrameEvent