本文概述
- AWT PopupMenu类声明
- Java AWT PopupMenu示例
AWT PopupMenu类声明
public class PopupMenu extends Menu implements MenuContainer, Accessible
Java AWT PopupMenu示例
import java.awt.*;
import java.awt.event.*;
class PopupMenuExample
{
PopupMenuExample(){
final Frame f= new Frame("PopupMenu Example");
final PopupMenu popupmenu = new PopupMenu("Edit");
MenuItem cut = new MenuItem("Cut");
cut.setActionCommand("Cut");
MenuItem copy = new MenuItem("Copy");
copy.setActionCommand("Copy");
MenuItem paste = new MenuItem("Paste");
paste.setActionCommand("Paste");
popupmenu.add(cut);
popupmenu.add(copy);
popupmenu.add(paste);
f.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
popupmenu.show(f , e.getX(), e.getY());
}
});
f.add(popupmenu);
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new PopupMenuExample();
}
}
输出:
文章图片
文章图片
推荐阅读
- Java AWT滚动条
- Windows 10的10大最佳Xbox 360模拟器推荐合集(你知道哪些())
- 13款用于在线评估的最佳开源考试软件推荐合集
- 如何将照片从Android传输到iPhone(实现方法分步指南)
- 16款最佳免费在线YouTube缩略图制作工具合集推荐
- 如何从Windows 10中的右键单击上下文菜单中删除项目()
- Win8.1安装photoshop提示“please uninstall”怎样办?
- Win8.1开机蓝屏报错“STOP:c0000221 unknown Hard Error”怎样办?
- Windows8.1玩大富翁4游戏画面显示不全怎样解?