Results 1 to 6 of 6

Thread: How to write an Internal Frame Listener in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    181

    How to write an Internal Frame Listener in Java?

    Hello friends,
    I am new to your forum. I have done some basic things in Java. But I am not able to write an internal frame..!!! I want a listener which would listen for an events that occur when the anything happens with the Window. Like if the windows has been shown for the first time, activated, or deactivated. Hope that you guys got the point that I am saying.! Please tell me how to write an Internal Frame Listener in Java.?? Help me soon as possible.
    Last edited by Soumen; 12-02-2010 at 11:59 PM.
    QTechnology Ultra-Quiet ATX PSU 460W I MSI K8N Neo4-F I AMD Opteron 144 CABNE0545 2.66Ghz I 2 x 512MB RAM I 380GB Maxtor SATAI Raid0 Hard Drive I 40GB Maxtor IDE Hard Drive I Nvidia GeForce 7900GTX I Win XP Home Service Pack 2 I Soundblaster Xtreme Fidelity Fatal1ty I Mercury Home Theater HT-4500

  2. #2
    Join Date
    Nov 2008
    Posts
    996

    Re: How to write an Internal Frame Listener in Java?

    Hi 'Soumen', Welcome to this forum...
    If you know about the WindowListener which is almost similar to an InternalFrameListener, then it would take no time for you to understand. As you know, when anything happens to the window that event is listened by the internal frame listener just like the window listener. The events of windows can be if it is shown for the first time, disposed of, iconified, deiconified, activated, or deactivated. You can say that internal frame listeners are very similar to WindowListeners and several Swing programs have window listeners.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to write an Internal Frame Listener in Java?

    I have provided you with the sample of the coding that requires InternalFrameEvent. Hope that you will get some help from this coding :
    Code:
    public InternalFrameEventTrial(String title) {
            super(title);
    
            desktop = new JDesktopPane();
            desktop.putClientProperty("JDesktopPane.dragMode",
                                      "outline");
    
            desktop.setPreferredSize(new Dimension(desktopWidth, desktopHeight));
            setContentPane(desktop);
    
            createDisplayWindow();
            desktop.add(displayWindow); 
            Dimension displaySize = displayWindow.getSize();
            displayWindow.setSize(desktopWidth, displaySize.height);
        }

  4. #4
    Join Date
    Mar 2008
    Posts
    349

    Re: How to write an Internal Frame Listener in Java?

    I am providing you the methods that are used for the InternalFrameListener Interface. Also an InternalFrameAdapter is the corresponding adapter class of this listener. The following are the methods of an InternalFrameListener Interface :
    • internalFrameOpened(InternalFrameEvent) - This method is called just after the listened-to internal frame has been shown for the first time.
    • internalFrameClosed(InternalFrameEvent) - When the listened-to internal frame has been disposed of, then this method is called.
    • internalFrameClosing(InternalFrameEvent) - This method is called in response to a user request that the listened-to internal frame be closed.
    • internalFrameIconified(InternalFrameEvent) - This method is called just after the listened-to internal frame is iconified.
    • internalFrameDeiconified(InternalFrameEvent) - When listened-to internal frame is deiconified then this method is called.

  5. #5
    Join Date
    Mar 2008
    Posts
    672

    Re: How to write an Internal Frame Listener in Java?

    I think that you will understand more after looking at the following code. The following code explains the internal frame event handling. So have a look on the code below :
    Code:
    public class InternalFrameEventTrial ...
    		     implements InternalFrameListener ... {
        ...
    
        public void internalFrameClosing(InternalFrameEvent ie) {
    	displayMessage("Internal frame closing", ie);
        }
    
        public void internalFrameClosed(InternalFrameEvent ie) {
    	displayMessage("Internal frame closed", ie);
    	listenedToWindow = null;
        }
    
        public void internalFrameOpened(InternalFrameEvent ie) {
    	displayMessage("Internal frame opened", ie);
        }
    
        public void internalFrameIconified(InternalFrameEvent ie) {
    	displayMessage("Internal frame iconified", ie);
        }
    
        public void internalFrameDeiconified(InternalFrameEvent ie) {
    	displayMessage("Internal frame deiconified", ie);
        }
    
        public void internalFrameActivated(InternalFrameEvent ie) {
    	displayMessage("Internal frame activated", ie);
        }
    
        public void internalFrameDeactivated(InternalFrameEvent ie) {
    	displayMessage("Internal frame deactivated", ie);
        }
    
        void displayMessage(String prefix, InternalFrameEvent ie) {
    	String str = prefix + ": " + ie.getSource(); 
    	display.append(str + newline);
        }
    
        public void actionPerformed(ActionEvent ie) {
    	if (SHOW.equals(ie.getActionCommand())) {
    	    ...
    	    if (listenedToWindow == null) {
    	        listenedToWindow = new JInternalFrame("Event Generator",
    	        				      true,  
    	        				      true,  
    	        				      true,  
    	        				      true);
            	listenedToWindow.setDefaultCloseOperation(
            				WindowConstants.HIDE_ON_CLOSE);
    
    	        listenedToWindow.addInternalFrameListener(this);
    	        ...
    	    }
    	} 
    	...
        }
    }

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to write an Internal Frame Listener in Java?

    I want to tell you more about the Internal Frame Listener which is used in Java. An AWTEvent that adds support for JInternalFrame objects as the event source. As said earlier the InternalFrame object is much similar to the WindowEvent, hence the JInternalFrame class has the same event types as WindowEvent but the only thing that they have different IDs for their use. One thing you would have to keep in mind that Swing which are going to release in future may have compatible issues with the Serialized objects of this class. Hope that this information was helpful for you.!!

Similar Threads

  1. How to write a Key Listener in Java?
    By N I C K in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 01:52 AM
  2. How to write a Container Listener in Java?
    By Pratim in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 06:43 AM
  3. How to write a Component Listener in Java?
    By hariharan_00 in forum Software Development
    Replies: 4
    Last Post: 12-02-2010, 06:28 AM
  4. How to write a Change Listener in Java?
    By Samarth in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 06:10 AM
  5. How to write a Caret Listener in Java?
    By Dilbert in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 05:33 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,726,941,528.16050 seconds with 17 queries