这个,我看你还是暴看看AWT吧!POPUP MEMU就是弹出式菜单啦!
比如,你可以在一个文本框中监听,当鼠标右建按下后,这个POPUP MEMU显示!

解决方案 »

  1.   

    我知道是弹出式菜单,难道必须监听鼠标消息吗,难道不能像delphi那样直接设置属性而得到吗???
      

  2.   

    package untitled5;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class Frame1 extends JFrame
    {
      JPanel contentPane;
      JButton jButton1 = new JButton();
      JPopupMenu jPopupMenu1 = new JPopupMenu();
      JMenuItem jMenuItem1 = new JMenuItem();
      JMenuItem jMenuItem2 = new JMenuItem();  //Construct the frame
      public Frame1()
      {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try
        {
          jbInit();
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception
      {
        //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        jButton1.setBounds(new Rectangle(119, 98, 79, 29));
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            jButton1_actionPerformed(e);
          }
        });
        contentPane.setLayout(null);
        this.setSize(new Dimension(400, 300));
        this.setTitle("Frame Title");
        jMenuItem1.setText("fdg");
        jMenuItem2.setText("gggg");
        jPopupMenu1.addSeparator();
        jPopupMenu1.add(jMenuItem1);
        jPopupMenu1.add(jMenuItem2);
        contentPane.add(jButton1, null);
      }
      //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e)
      {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING)
        {
          System.exit(0);
        }
      }  void jButton1_actionPerformed(ActionEvent e)
      {
         jPopupMenu1.show(this,90,90);
      }
    }