Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Standard way of creating a popup menu on mouse right click

Hi,

What's the accepted/standard way to create a popup menu in java when the user right clicks your applet? I'd prefer something very lightwieght, I just need the bare minimum,

Thanks
0
DJ_AM_Juicebox
Asked:
DJ_AM_Juicebox
  • 2
1 Solution
 
DJ_AM_JuiceboxAuthor Commented:
Yeah im not using swing, its just a plain old double buffered drawing applet:

import java.awt.*;

public abstract class BufferedApplet extends java.applet.Applet implements Runnable
{
0
 
UrosVidojevicCommented:
import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class PopupMenuTest extends Applet implements ActionListener {

      PopupMenu popup;

      public void init() {         
            MenuItem mi;

          popup = new PopupMenu("Edit");

            mi = new MenuItem("Cut");
            mi.addActionListener(this);
          popup.add(mi);

            mi = new MenuItem("Copy");
            mi.addActionListener(this);
          popup.add(mi);

          popup.addSeparator();

            mi = new MenuItem("Paste");
            mi.addActionListener(this);
          popup.add(mi);

          add(popup); // add popup menu to applet
           
            enableEvents(AWTEvent.MOUSE_EVENT_MASK);

          resize(200, 200);
        }

      public void processMouseEvent(MouseEvent e) {

          if (e.isPopupTrigger()) {
              popup.show(e.getComponent(), e.getX(), e.getY());
          }
          super.processMouseEvent(e);
        }

        public void actionPerformed(ActionEvent e) {
          String command = e.getActionCommand();

            if (command.equals("Cut")) {
              // perform cut operation
            } else if (command.equals("Copy")) {
                // perform copy operation
            } else if (command.equals("Paste")) {
                // perform paste operation
            }
        }
    }
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now