FileDocCategorySizeDatePackage
MenuElementExample.javaAPI DocExample3058Mon Nov 09 12:45:48 GMT 1998None

MenuElementExample

public class MenuElementExample extends JPanel implements MouseListener, ActionListener, PopupMenuListener

Fields Summary
public JPopupMenu
popup
SliderMenuItem
slider
int
theValue
Constructors Summary
public MenuElementExample()


      

        popup = new JPopupMenu(); 
        slider = new SliderMenuItem();

        popup.add(slider);
        popup.add(new JSeparator());

        JMenuItem ticks = new JCheckBoxMenuItem("Slider Tick Marks");
        JMenuItem labels = new JCheckBoxMenuItem("Slider Labels");
        ticks.addActionListener(this);
        labels.addActionListener(this);

        popup.add(ticks);
        popup.add(labels);
        popup.addPopupMenuListener(this);

        addMouseListener(this);
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

         if (event.getActionCommand() == "Slider Tick Marks")
             slider.setPaintTicks(!slider.getPaintTicks());
         if (event.getActionCommand() == "Slider Labels")
             slider.setPaintLabels(!slider.getPaintLabels());
    
public static voidmain(java.lang.String[] s)

        JFrame frame = new JFrame("Menu Element Example");
        frame.addWindowListener(new BasicWindowMonitor());
        frame.setContentPane(new MenuElementExample());
        frame.setSize(300, 300);
        frame.setVisible(true);
    
public voidmouseClicked(java.awt.event.MouseEvent e)

 popupCheck(e); 
public voidmouseEntered(java.awt.event.MouseEvent e)

public voidmouseExited(java.awt.event.MouseEvent e)

public voidmousePressed(java.awt.event.MouseEvent e)

 popupCheck(e); 
public voidmouseReleased(java.awt.event.MouseEvent e)

 popupCheck(e); 
private voidpopupCheck(java.awt.event.MouseEvent e)

        if (e.isPopupTrigger()) { 
            popup.show(this, e.getX(), e.getY());
        } 
    
public voidpopupMenuCanceled(javax.swing.event.PopupMenuEvent e)

        System.out.println("Popup menu is hidden!");
    
public voidpopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent e)

        theValue = slider.getValue();
        System.out.println("The value is now " + theValue);
    
public voidpopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent e)