Topic: 如何实现鼠标右键..弹出菜单?

  Print this page

1.如何实现鼠标右键..弹出菜单? Copy to clipboard
Posted by: LLL_QQQ
Posted on: 2004-09-25 01:57

如何实现鼠标右键..弹出菜单?

需要附在窗体f上.
继承哪个Adapter?
f.add......Listener?

谢谢!

2.Re:如何实现鼠标右键..弹出菜单? [Re: LLL_QQQ] Copy to clipboard
Posted by: lpp333
Posted on: 2004-09-26 23:41

怎么没人回答

3.Re:如何实现鼠标右键..弹出菜单? [Re: LLL_QQQ] Copy to clipboard
Posted by: LLL_QQQ
Posted on: 2004-09-27 12:31

WHY?
WHY?
WHY?

4.Re:如何实现鼠标右键..弹出菜单? [Re: LLL_QQQ] Copy to clipboard
Posted by: floater
Posted on: 2004-09-27 21:35

JPopupMenu

check sun's tutorial

5.Re:如何实现鼠标右键..弹出菜单? [Re: LLL_QQQ] Copy to clipboard
Posted by: littledeer1974
Posted on: 2004-09-28 09:07

我做了个例子大家来完善一下吧


import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;

public class question09 extends JFrame implements MouseListener {
JPopupMenu popmenu;

question09() {
JPanel panel = new JPanel();
//set the coloer of the panel
panel.setBackground(new Color(34, 45, 122));
panel.addMouseListener(this);
//
popmenu = new JPopupMenu();
this.prepareMenu();
//
panel.add(popmenu);

this.getContentPane().add(panel);

this.setSize(400, 400);
this.show();
}

//
public void prepareMenu() {
JMenuItem item01 = new JMenuItem("test item 01");
JMenuItem item02 = new JMenuItem("test item 02");
popmenu.add(item01);
popmenu.add(item02);

}

//
public void mouseClicked(MouseEvent e) {
}

//
public void mouseEntered(MouseEvent e) {
}

//
public void mouseExited(MouseEvent e) {
}

//
public void mousePressed(MouseEvent e) {
//if the button is the right button
if (e.getButton() == 3) {
popmenu.show(this, e.getX(), e.getY());
}

}

//
public void mouseReleased(MouseEvent e) {
}

///////////////////////////////////////
public static void main(String[] args) {
question09 test = new question09();
}

}

6.Re:如何实现鼠标右键..弹出菜单? [Re: LLL_QQQ] Copy to clipboard
Posted by: LLL_QQQ
Posted on: 2004-09-28 14:00

Thanks ,littledeer1974.......
^_^

7.Re:如何实现鼠标右键..弹出菜单? [Re: LLL_QQQ] Copy to clipboard
Posted by: littledeer1974
Posted on: 2004-09-28 14:53

WinkSmile


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923