jb 中popup menu 如何使用??

hazel 2002-04-03 12:33:45
初学java 请问 jb5 中popup menu 如何使用??
能详细点吗??
...全文
144 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengji 2002-04-03
  • 打赏
  • 举报
回复
这个,我看你还是暴看看AWT吧!POPUP MEMU就是弹出式菜单啦!
比如,你可以在一个文本框中监听,当鼠标右建按下后,这个POPUP MEMU显示!
lczddd 2002-04-03
  • 打赏
  • 举报
回复
楼上的,干什么啊,呵呵
hexiaofeng 2002-04-03
  • 打赏
  • 举报
回复
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);
}
}
hazel 2002-04-03
  • 打赏
  • 举报
回复
我知道是弹出式菜单,难道必须监听鼠标消息吗,难道不能像delphi那样直接设置属性而得到吗???

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧