Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
If you right-click on one of the components, a contextmenu will be shown containing 2 choices : set color and delete component. This way, each component can have its color set or be removed.
Reference variables to the menu and its items .
Creation of instances in the constructor.
Add items to the menu .
The menu-items have to call this applet instance's actionPerformed method , when chosen.
Create and initialize three components.
This instance's mouse methods have to be called by them.
Our pop method is called from both the mousePressed AND the mouseReleased method, due to platform differences.
See if the mouse event was a context-menu event.
Every visual component derives from java.awt.Component, so we can save a reference like this.
to show the context-menu in the right place .
When a menu-item is chosen, the applet's actionPerformed method is called. We immediately get the source of the action event :
See if it was the first MenuItem, at the same time checking if the Component reference refers to something .
The component's color is set using the reference we saved earlier ....
and leave the method.
If the other menu-item was chosen, the component is removed from the contentpane and its reference is set to null.
Update the contentpane's layout ...
add vs. remove
Both inherited from Container.