FileDocCategorySizeDatePackage
PopUpColorMenu2.javaAPI DocExample1652Sat Apr 23 22:35:30 BST 2005None

PopUpColorMenu2

public class PopUpColorMenu2 extends Object implements ActionListener

Fields Summary
Constructors Summary
public PopUpColorMenu2()

    JFrame frame = new JFrame("PopUpColorMenu v2.0");

	JPanel panel = new JPanel();
    JButton button = new JButton("Uno");
	button.setInheritsPopupMenu(true);
    panel.add(button);
    button = new JButton("Due");
	button.setInheritsPopupMenu(true);
    panel.add(button);
    button = new JButton("Tre");
	button.setInheritsPopupMenu(true);
    panel.add(button);

  	final JPopupMenu colorMenu = new JPopupMenu("Color");
    colorMenu.add(makeMenuItem("Red"));
    colorMenu.add(makeMenuItem("Green"));
    colorMenu.add(makeMenuItem("Blue"));
	panel.setComponentPopupMenu( colorMenu );
	panel.setBackground(Color.BLUE);

	frame.setBackground( Color.RED );
	frame.add( BorderLayout.CENTER, panel );
	frame.setSize(200,50);
	frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.setVisible(true);
  
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

  	System.out.println( e );
  	System.out.println( e.getSource() );
	/*
    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 static voidmain(java.lang.String[] args)

     new PopUpColorMenu2();
  
private javax.swing.JMenuItemmakeMenuItem(java.lang.String label)

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