maybeShowPopup(e)是什么意思啊?查API没查到谢谢~
程序8-12:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class PopupMenuDemo extends MouseAdapter
implements ActionListener{
JFrame frame = new JFrame ("Popup Menu Demo");
JPopupMenu popup = new JPopupMenu();
JTextField tf = new JTextField();
JLabel label = new JLabel("Try to click left and right button"); public static void main(String args[]) {
PopupMenuDemo popupMenuDemo = new PopupMenuDemo();
popupMenuDemo.go();
} public void go() {
//弹出式菜单中的菜单项
JMenuItem menuItem = new JMenuItem("New",KeyEvent.VK_N);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Load",KeyEvent.VK_L);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Save",KeyEvent.VK_S);
menuItem.addActionListener(this);
popup.add(menuItem);
popup.addSeparator(); //加入分隔线
menuItem = new JMenuItem("Copy",KeyEvent.VK_C);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Cut",KeyEvent.VK_T);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Paste",KeyEvent.VK_P);
menuItem.addActionListener(this);
popup.add(menuItem);
label.addMouseListener(this);
tf.setEditable(false); //设置为不可编辑的 Container cp = frame.getContentPane();
cp.add(label,BorderLayout.CENTER);
cp.add(tf,BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,200);
frame.setVisible(true);
} //改写MouseAdapter中的方法
public void mousePressed(MouseEvent e) {
maybeShowPopup(e);
} public void mouseReleased(MouseEvent e) {
maybeShowPopup(e);
} private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()){ //判断是否单击了引发弹出式菜单的鼠标键
popup.show(e.getComponent(),
e.getX(), e.getY());
}
} // 实现ActionListener接口中的方法
public void actionPerformed(ActionEvent e) {
tf.setText(e.getActionCommand());
if (e.getActionCommand()=="Exit") {
System.exit(0);
}
}
}
程序8-12:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class PopupMenuDemo extends MouseAdapter
implements ActionListener{
JFrame frame = new JFrame ("Popup Menu Demo");
JPopupMenu popup = new JPopupMenu();
JTextField tf = new JTextField();
JLabel label = new JLabel("Try to click left and right button"); public static void main(String args[]) {
PopupMenuDemo popupMenuDemo = new PopupMenuDemo();
popupMenuDemo.go();
} public void go() {
//弹出式菜单中的菜单项
JMenuItem menuItem = new JMenuItem("New",KeyEvent.VK_N);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Load",KeyEvent.VK_L);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Save",KeyEvent.VK_S);
menuItem.addActionListener(this);
popup.add(menuItem);
popup.addSeparator(); //加入分隔线
menuItem = new JMenuItem("Copy",KeyEvent.VK_C);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Cut",KeyEvent.VK_T);
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Paste",KeyEvent.VK_P);
menuItem.addActionListener(this);
popup.add(menuItem);
label.addMouseListener(this);
tf.setEditable(false); //设置为不可编辑的 Container cp = frame.getContentPane();
cp.add(label,BorderLayout.CENTER);
cp.add(tf,BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,200);
frame.setVisible(true);
} //改写MouseAdapter中的方法
public void mousePressed(MouseEvent e) {
maybeShowPopup(e);
} public void mouseReleased(MouseEvent e) {
maybeShowPopup(e);
} private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()){ //判断是否单击了引发弹出式菜单的鼠标键
popup.show(e.getComponent(),
e.getX(), e.getY());
}
} // 实现ActionListener接口中的方法
public void actionPerformed(ActionEvent e) {
tf.setText(e.getActionCommand());
if (e.getActionCommand()=="Exit") {
System.exit(0);
}
}
}
解决方案 »
- 新人求助 jdbc Access 连接不上
- J2EE方面的一些小问题,希望高手进来看看
- juilder9 连接sql server 2000的问题
- java中有没有提供专门的排序类呢?除Collections类
- socket的面试题求解
- 承接软件组件开发,Q_Q:570659699
- java不是已经开源了吗?
- 关于file
- 在java怎么连接不在一个防火墙的远程SQL Sever服务器??和局域网内的有什么区别??100分请叫高手
- 100分给高手的难题:如何使用Socket正确无误的发送ClientDataSet.data数据到客户端?
- 请教关于java反射的问题。
- java程序求帮忙,在线等,谢谢大家
private void maybeShowPopup(MouseEvent e) {
if (e.isPopupTrigger()){ //判断是否单击了引发弹出式菜单的鼠标键
popup.show(e.getComponent(),
e.getX(), e.getY());
}
}