java中鼠标右击弹出菜单怎么实现
展开全部
简单的实现代码如下:
import java.awt.MenuBar;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
/*
* java中鼠标右击弹出菜单怎样实现
*/
public class Demo {
public static void main(String[] args) {
final JFrame jf = new JFrame("窗体");
jf.setSize(300, 300);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLocationRelativeTo(null);
// 创建弹出菜单
final JPopupMenu jp = new JPopupMenu();
jp.add("红色");
jp.add("蓝色");
jf.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询