/** * @(#)DrawPanel.java * * This is an interactive applet. Allows the user to select a color from, * the popupmenu. Click in the panel or as mouse enters or exits applet, draw * circles at mouse location. */ import java.awt.*; import java.applet.*; import java.awt.event.*; import java.lang.Class; /** * Draw Panel * Implements Action listener. An array (colorNames) is used to store the Names * of the colors to be listed in the menu. A second array (colors) is used to * store the Color value associated with the string value in colorNames. Sets * the Color value using ActionListener. MouseEvent is used to detect whether or * not the mouse event is the popupTrigger for the popup-menu. This will show the * color menu at the location clicked in the applet. Then mouse event used to * draw circles (left mouse click) at the location clicked or on entering and * exiting the applet. * * @param: Input: None */ public class DrawPanel extends Applet implements ActionListener{ /** Initalize a String array with labels for the colors in the menu */ private String[] colorNames ={"Black", "Cyan","Green", "Magenta","Orange"}; /** Initalize a Color array with color values in the menu */ private Color[] colors = {Color.black,Color.cyan, Color.green, Color.magenta, Color.orange}; private PopupMenu menu; /** Create popup menu and add items */ public void init(){ setBackground(Color.white); menu = new PopupMenu(); /** Enable mouse events */ enableEvents(AWTEvent.MOUSE_EVENT_MASK); MenuItem colorName; /** Add items to the menu and add action Listener to each item */ for(int i=0; i