Solved

Standard way of creating a popup menu on mouse right click

Posted on 2007-12-01
4
269 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 7

Expert Comment

by:UrosVidojevic
ID: 20388596
0
 
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 500 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

752 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