Abstract Class ContainerAdapter in Java

0
241
Spread the love
  • 29
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    166
    Shares

Abstract Class ContainerAdapter in Java

ContainerAdapter class is an implementation of the ContainerListener interface containing empty bodies of each method of the ContainerListener interface. If we do not wish to write every method of the ContainerListener interface in our class, the ContainerAdapter class helps in that aspect.

The ContainerAdapter class implements the methods of ContainerListener with empty
functions. It may be easier for us to extend ContainerAdapter, overriding only those methods we are interested in than to implement ContainerListener and provide the empty functions ourselves.

The structure of interface ContainerAdapter is given as:

public abstract class java.awt.event.ContainerAdapter extends java.lang.Object implements java.awt.event.ContainerListener {
//constructor
public ContainerAdapter();
//methods
public void componentAdded(ContainerEvent e);
public void componentRemoved(ContainerEvent e);
} 

The details of the class structure are given as follows:

public void componentAdded(ContainerEvent e);

public void componentAdded(ContainerEvent e) method actually does nothing. We need to override this function to be notified when a component is added to a container.

Parameter
e – The event that has occurred.

public void componentRemoved(ContainerEvent e);

public void componentRemoved(ContainerEvent e) method actually does nothing. We need to override this function to be notified when a component is removed from a container.

Parameter
e – The event that has occurred.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 29
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    166
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here