Pages

Friday, 20 May 2011

pop up menu in java

import javax.swing.*;
import java.awt.event.*;

public class PopUpMenu{
    JPopupMenu Pmenu;
    JMenuItem menuItem;
    public static void main(String[] args) {
        PopUpMenu p = new PopUpMenu();
    }

    public PopUpMenu(){
        JFrame frame = new JFrame("Creating a Popup Menu");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Pmenu = new JPopupMenu();
        menuItem = new JMenuItem("Cut");
        Pmenu.add(menuItem);
        menuItem = new JMenuItem("Copy");
        Pmenu.add(menuItem);
        menuItem = new JMenuItem("Paste");
        Pmenu.add(menuItem);
        menuItem = new JMenuItem("Delete");
        Pmenu.add(menuItem);
        menuItem = new JMenuItem("Undo");
        Pmenu.add(menuItem);
        menuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){}
            });
        frame.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent me){
                if(me.isPopupTrigger()){
                    Pmenu.show(me.getComponent(), me.getX(), me.getY());
                }
            }
            public void mouseReleased(MouseEvent Me){
                if(Me.isPopupTrigger()){
                    Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
                }
            }
        });
        frame.setSize(400,400);
        frame.setVisible(true);
    }
}

7 comments:

  1. wonderful submit, very informative. I ponder why the opposite specialists
    of this sector do not notice this. You must proceed your writing.
    I'm confident, you've a huge readers' base already!

    Here is my web page ... hardwood floor

    ReplyDelete
  2. If you would like to obtain much from this piece of
    writing then you have to apply these methods to your won website.


    installing hardwood floors

    Here is my web-site; cleaning hardwood floors

    ReplyDelete
  3. Appreciating the persistence you put into your blog and in depth information you provide.

    It's good to come across a blog every once in a while that isn't the same old
    rehashed material. Fantastic read! I've saved your site and I'm adding
    your RSS feeds to my Google account.

    my site: wood floors

    ReplyDelete
  4. It's an awesome post for all the web people; they will take benefit from it I am sure.

    Here is my website hardwood floors

    ReplyDelete
  5. I've been surfing online greater than 3 hours lately, but I by no means found any interesting article like yours. It's beautiful price enough for me.
    In my view, if all webmasters and bloggers made just right content as you probably did,
    the internet might be a lot more helpful than ever before.



    my web page; cleaning melbourne

    ReplyDelete
  6. Wow, this post is fastidious, my sister is analyzing these things, so I
    am going to convey her.

    my blog post; provillusreviews-hq.blogspot.com

    ReplyDelete
  7. It's wonderful that you are getting thoughts from this article as well as from our argument made at this time.

    My blog ... veterinarycontinuingeducation.com
    my web site - provillus information

    ReplyDelete