Implements InternalFrameListener : InternalFrame « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Swing JFC » InternalFrameScreenshots 
Implements InternalFrameListener
Implements InternalFrameListener

/* From http://java.sun.com/docs/books/tutorial/index.html */

/*
 * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * -Redistribution of source code must retain the above copyright notice, this
 *  list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduce the above copyright notice,
 *  this list of conditions and the following disclaimer in the documentation
 *  and/or other materials provided with the distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that this software is not designed, licensed or intended
 * for use in the design, construction, operation or maintenance of any
 * nuclear facility.
 */

/*
 * InternalFrameEventDemo.java is a 1.4 example that requires no other files.
 */

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

public class InternalFrameEventDemo extends JFrame implements
    InternalFrameListener, ActionListener {
  JTextArea display;

  JDesktopPane desktop;

  JInternalFrame displayWindow;

  JInternalFrame listenedToWindow;

  static final String SHOW = "show";

  static final String CLEAR = "clear";

  String newline = "\n";

  static final int desktopWidth = 500;

  static final int desktopHeight = 300;

  public InternalFrameEventDemo(String title) {
    super(title);

    //Set up the GUI.
    desktop = new JDesktopPane();
    desktop.putClientProperty("JDesktopPane.dragMode""outline");
    //Because we use pack, it's not enough to call setSize.
    //We must set the desktop's preferred size.
    desktop.setPreferredSize(new Dimension(desktopWidth, desktopHeight));
    setContentPane(desktop);

    createDisplayWindow();
    desktop.add(displayWindow)//DON'T FORGET THIS!!!
    Dimension displaySize = displayWindow.getSize();
    displayWindow.setSize(desktopWidth, displaySize.height);
  }

  //Create the window that displays event information.
  protected void createDisplayWindow() {
    JButton b1 = new JButton("Show internal frame");
    b1.setActionCommand(SHOW);
    b1.addActionListener(this);

    JButton b2 = new JButton("Clear event info");
    b2.setActionCommand(CLEAR);
    b2.addActionListener(this);

    display = new JTextArea(330);
    display.setEditable(false);
    JScrollPane textScroller = new JScrollPane(display);
    //Have to supply a preferred size, or else the scroll
    //area will try to stay as large as the text area.
    textScroller.setPreferredSize(new Dimension(20075));
    textScroller.setMinimumSize(new Dimension(1010));

    displayWindow = new JInternalFrame("Event Watcher", true, //resizable
        false, //not closable
        false, //not maximizable
        true)//iconifiable
    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(10101010));
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    b1.setAlignmentX(CENTER_ALIGNMENT);
    contentPane.add(b1);
    contentPane.add(Box.createRigidArea(new Dimension(05)));
    contentPane.add(textScroller);
    contentPane.add(Box.createRigidArea(new Dimension(05)));
    b2.setAlignmentX(CENTER_ALIGNMENT);
    contentPane.add(b2);

    displayWindow.setContentPane(contentPane);
    displayWindow.pack();
    displayWindow.setVisible(true);
  }

  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);
  }

  //Add some text to the text area.
  void displayMessage(String prefix, InternalFrameEvent e) {
    String s = prefix + ": " + e.getSource();
    display.append(s + newline);
    display.setCaretPosition(display.getDocument().getLength());
  }

  //Handle events on the two buttons.
  public void actionPerformed(ActionEvent e) {
    if (SHOW.equals(e.getActionCommand())) {
      //They clicked the Show button.

      //Create the internal frame if necessary.
      if (listenedToWindow == null) {
        listenedToWindow = new JInternalFrame("Event Generator", true, //resizable
            true, //closable
            true, //maximizable
            true)//iconifiable
        //We want to reuse the internal frame, so we need to
        //make it hide (instead of being disposed of, which is
        //the default) when the user closes it.
        listenedToWindow
            .setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

        //Add an internal frame listener so we can see
        //what internal frame events it generates.
        listenedToWindow.addInternalFrameListener(this);

        //And we mustn't forget to add it to the desktop pane!
        desktop.add(listenedToWindow);

        //Set its size and location. We'd use pack() to set the size
        //if the window contained anything.
        listenedToWindow.setSize(300100);
        listenedToWindow.setLocation(desktopWidth / 2
            - listenedToWindow.getWidth() 2, desktopHeight
            - listenedToWindow.getHeight());
      }

      //Show the internal frame.
      listenedToWindow.setVisible(true);

    else //They clicked the Clear button.
      display.setText("");
    }
  }

  /**
   * Create the GUI and show it. For thread safety, this method should be
   * invoked from the event-dispatching thread.
   */
  private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new InternalFrameEventDemo("InternalFrameEventDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
  }

  public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createAndShowGUI();
      }
    });
  }
}

           
       
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. InternalFrame TestInternalFrame Test
7. JDesktopPane Cascade DemoJDesktopPane Cascade Demo
8. Java X WindowsJava X Windows
9. Desktop Manager DemoDesktop Manager Demo
10. Internal Frame Listener Demo Internal Frame Listener Demo
11. Layered Pane DemoLayered Pane Demo
12. LayeredPane Demo 2: Custom MDILayeredPane Demo 2: Custom MDI
13. LayeredPane Demo 3: Custom MDILayeredPane Demo 3: Custom MDI
14. LayeredPane Demo 4: Custom MDILayeredPane Demo 4: Custom MDI
15. InternalFrame demoInternalFrame demo
16. InternalFrameEvent DemoInternalFrameEvent Demo
17. A few interesting things using JInternalFrames, JDesktopPane, and DesktopManagerA few interesting things using JInternalFrames, JDesktopPane, and DesktopManager
18. A quick setting up an Internal Frame in an applicationA quick setting up an Internal Frame in an application
19. Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2
w_ww__.___ja_v__a___2_s__.___c__om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.