InternalFrameEvent Demo : InternalFrame « Swing JFC « Java






InternalFrameEvent Demo

InternalFrameEvent Demo
  
import java.awt.BorderLayout;
import java.awt.Container;

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

public class InternalFrameEventTest {
  public static void main(String[] a) {

    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    JLayeredPane desktop = new JDesktopPane();
    desktop.setOpaque(false);
    contentPane.add(desktop, BorderLayout.CENTER);
    desktop.add(createLayer("One"), JLayeredPane.POPUP_LAYER);
    desktop.add(createLayer("Two"), JLayeredPane.DEFAULT_LAYER);
    desktop.add(createLayer("Three"), JLayeredPane.PALETTE_LAYER);

    frame.setSize(400, 200);
    frame.setVisible(true);

  }

  public static JInternalFrame createLayer(String label) {
    return new SelfInternalFrame(label);
  }

}

class SelfInternalFrame extends JInternalFrame {
  public SelfInternalFrame(String s) {
    getContentPane().add(new JLabel(s), BorderLayout.CENTER);
    addInternalFrameListener(new InternalFrameListener() {
      public void internalFrameActivated(InternalFrameEvent e) {
        System.out.println("Activated" + e.getSource());
      }

      public void internalFrameClosed(InternalFrameEvent e) {
        System.out.println("Closed");
      }

      public void internalFrameClosing(InternalFrameEvent e) {
        System.out.println("Closing");
      }

      public void internalFrameDeactivated(InternalFrameEvent e) {
        System.out.println("Deactivated");
      }

      public void internalFrameDeiconified(InternalFrameEvent e) {
        System.out.println("Deiconified");
      }

      public void internalFrameIconified(InternalFrameEvent e) {
        System.out.println("Iconified");
      }

      public void internalFrameOpened(InternalFrameEvent e) {
        System.out.println("Opened");
      }
    });
    setBounds(50, 50, 100, 100);
    setResizable(true);
    setClosable(true);
    setMaximizable(true);
    setIconifiable(true);
    setTitle(s);
  }
}

           
         
    
  








Related examples in the same category

1.A quick demonstration of setting up an internal frame in an applicationA quick demonstration of setting up an internal frame in an application
2.A simple extension of the JInternalFrame class that contains a list
3.JDesktopPane demoJDesktopPane demo
4.Working with Internal Frames within a Desktop
5.Internal Frames DemoInternal Frames Demo
6.JDesktopPane Cascade DemoJDesktopPane Cascade Demo
7.Java X WindowsJava X Windows
8.Desktop Manager DemoDesktop Manager Demo
9.Internal Frame Listener Demo Internal Frame Listener Demo
10.Layered Pane DemoLayered Pane Demo
11.LayeredPane Demo 2: Custom MDILayeredPane Demo 2: Custom MDI
12.LayeredPane Demo 3: Custom MDILayeredPane Demo 3: Custom MDI
13.LayeredPane Demo 4: Custom MDILayeredPane Demo 4: Custom MDI
14.Implements InternalFrameListenerImplements InternalFrameListener
15.InternalFrame demoInternalFrame demo
16.A few interesting things using JInternalFrames, JDesktopPane, and DesktopManagerA few interesting things using JInternalFrames, JDesktopPane, and DesktopManager
17.A quick setting up an Internal Frame in an applicationA quick setting up an Internal Frame in an application
18.Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2
19.Make a JInternalFrame a tool window
20.Move JInternalFrame To Front
21.This program demonstrates the use of internal framesThis program demonstrates the use of internal frames