FileDocCategorySizeDatePackage
PopupColorMenu.javaAPI DocExample1563Sat Mar 07 02:25:46 GMT 1998None

PopupColorMenu

public class PopupColorMenu extends Applet implements ActionListener

Fields Summary
PopupMenu
colorMenu
Component
selectedComponent
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

		String color = e.getActionCommand();
		if ( color.equals("Red") )
			selectedComponent.setBackground( Color.red );
		else if ( color.equals("Green") )
			selectedComponent.setBackground( Color.green );
		else if ( color.equals("Blue") )
			selectedComponent.setBackground( Color.blue );
	
public voidinit()

        
		MouseAdapter adapter = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if ( e.isPopupTrigger() ) {
					selectedComponent = getComponentAt( e.getX(), e.getY() );
					colorMenu.show(e.getComponent(), e.getX(), e.getY());
				}
			}
		};

		Button button = new Button("One");
		button.addMouseListener( adapter );
		add( button );
		button = new Button("Two");
		button.addMouseListener( adapter );
		add( button );
		button = new Button("Three");
		button.addMouseListener( adapter );
		add( button );
		
		colorMenu = new PopupMenu("Color");
		colorMenu.add( makeMenuItem("Red") );
		colorMenu.add( makeMenuItem("Green") );
		colorMenu.add( makeMenuItem("Blue") );


		add(colorMenu);
    
private java.awt.MenuItemmakeMenuItem(java.lang.String label)

		MenuItem item = new MenuItem(label);
		item.addActionListener( this );
		return item;