Java Code Examples for java.awt.event.ContainerEvent

Following code examples demonstrate how to use java.awt.event.ContainerEventfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.awt.event.ContainerEventand various code implementation of this class.

      public void componentAdded(ContainerEvent e) {
         log.trace("component added: "+e.getChild());
         Component newComp = e.getChild();
         
         storeIfNamed(newComp);

      } 


      public void componentRemoved(ContainerEvent e) {
         log.trace("component removed: "+e.getChild());
         _namedComponents.remove(e.getChild());
      } 

    public void componentAdded(ContainerEvent ev) {
        Component child = ev.getChild();
        Container cont = ev.getContainer();

        addChild(cont, child);
    } 

    public void componentRemoved(ContainerEvent ev) {
        Component child = ev.getComponent();
        map.remove(child);
    } 

	protected void processContainerEvent(ContainerEvent arg0) {
		if(arg0.getID()==Message.next_level){
		synchronized (this) {
			try {
				new MainFrame(this.level + 1,this.speed,this.ori);
				
				this.wait();
				this.dispose();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		this.dispose();
	
		}
		super.processContainerEvent(arg0);
	} 

    public static void main(String args[]) {
        
        
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Ejemplo_ContainerEvent.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Ejemplo_ContainerEvent.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Ejemplo_ContainerEvent.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Ejemplo_ContainerEvent.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ejemplo_ContainerEvent().setVisible(true);
            }
        });
    } 

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to ContainerEvent.class!",
                   ContainerEvent.class.isAssignableFrom(sut));
    } 

Advertisement
Javadoc
A low-level event which indicates that a container's contents changed because a component was added

or removed. Container events are provided for notification purposes ONLY; The AWT will automatically handle changes to the containers contents internally so that the program works properly regardless of whether the program is receiving these events or not. This low-level event is generated by a container object (such as a Panel) when a component is added to it or removed from it. The event is passed to every ContainerListener or ContainerAdapter object which registered to receive such events using the component's addContainerListener method. (ContainerAdapter objects implement the ContainerListener interface.) Each such listener object gets this ContainerEvent when the event occurs.

An unspecified behavior will be caused if the id parameter of any particular ContainerEvent instance is not in the range from CONTAINER_FIRST to CONTAINER_LAST. @see ContainerAdapter @see ContainerListener @see Tutorial: Writing a Container Listener @author Tim Prinzing @author Amy Fowler @since 1.1

Read More
Advertisement