Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Standard way of creating a popup menu on mouse right click

Posted on 2007-12-01
4
Medium Priority
?
281 Views
Last Modified: 2011-09-20
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
Comment
Question by:DJ_AM_Juicebox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 20388597
0
 

Author Comment

by:DJ_AM_Juicebox
ID: 20388683
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
 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 2000 total points
ID: 20388690
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question