请问怎样或的鼠标右击事件?具体是这样的,我做了个QQ聊天的程序,在主窗口,好友列表那,我想右击好友头像后,让他出现JPopupMenu。哪位大狭告诉小弟,在线等了
解决方案 »
- 在java中如何用byte表示一个十六进制的数据
- 我的Hello类部在任何包中,而Test类却在包my.test中调用的问题
- Eclipse的ve插件是不是不能安装在jdk1.5环境下?昨天用eclipse3.1.1+emf-sdo-runtime2.1+GEF-runtime3.1+VE-runtime1.1.0.1始终不成功
- 这是什么数字?
- 关于事件适配器的简单问题。急。。
- SWT 事件处理,大神路过别走,在线急求指导
- 如何解决Solaris8&JDK1.4.2_06下JSP乱码问题
- JAVA程序封装问题---急用加高分(200分)
- UPD组包问题,请教各位大侠
- java中如何调用com?急,送分
- 用JAVA自带的jTree1组件,在组件上添加右键弹出菜单,删除选中节点。
- 使用就jacob操作word文件时 如何将文件路径改为相对路径
if(e.isPopupTrigger()){
popupMenu.show(e.getComponent(),e.getX,e.getY());
}
}
建议用NetBeans,用起来你就知道怎么来了,很简单,跟.Net里面的验证控件一样,
连接一下就可以了。
楼主【yulu0214】截止到2008-07-03 14:37:11的历史汇总数据(不包括此帖):
发帖的总数量:5 发帖的总分数:150
结贴的总数量:4 结贴的总分数:130
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:20
结贴的百分比:80.00 % 结分的百分比:86.67 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
//判断是否是右击
if(e.getButton()==3){
//设置右键菜单出现的位置
this.jPopupMenu1.show(this,e.getX(),e.getY());
}
}
public void mousePressed(final MouseEvent e) {
//MouseEvent.BUTTON1是左键 MouseEvent.BUTTON2是中键MouseEvent.BUTTON3右键
int button=e.getButton();
if (button == MouseEvent.BUTTON1)
{
........
} else if (button == MouseEvent.BUTTON2)
{
........
} else if (button == MouseEvent.BUTTON3)
{
..................
}
else
{
myJxta.setTextContent("发送鼠标点击事件的用户不存在");
}
}
});
/**
* @(#)MenuTestt.java
*
*
* @author
* @version 1.00 2008/7/15
*/// MenuTest.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MenuTestt extends JFrame
{ JLabel lbl=new JLabel();
JPanel p=new JPanel();
JPopupMenu popup = new JPopupMenu();
JMenuItem item1 = new JMenuItem("Click111");
JMenuItem item2 = new JMenuItem("Click222");
JMenuItem item3 = new JMenuItem("Click333");
public MenuTestt() {
super("JPopupMenu");
popup.add(item1);
popup.add(item2);
popup.add(item3);
p.add(lbl);
p.add(popup);
this.add(p);
item1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
lbl.setText("Click111");
}
});
item2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
lbl.setText("Click222");
}
});
item3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
lbl.setText("Click333");
}
});
p.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent event){
if(event.isPopupTrigger()){
popup.show(event.getComponent(),event.getX(),event.getY());
}
}
});
this.setVisible(true);
this.setSize(200,200);
}
public static void main (String[] args) {
new MenuTestt();
}
}