日期:2014-05-20 浏览次数:20766 次
private JPopupMenu pMenu;
private JMenuItem mSelectAll;
private JMenuItem mCopy;
private JMenuItem mCut;
private JMenuItem mSelectAll;
private JMenuItem mCopy;
private JMenuItem mCut;
mSelectAll.addMouseMotionListener(this);
mCopy.addMouseMotionListener(this);
mCut.addMouseMotionListener(this);
mSelectAll.addActionListener(this);
mCopy.addActionListener(this);
mCut.addActionListener(this);
pMenu.add(mSelectAll);
pMenu.add(mCopy);
pMenu.add(mCut);
pMenu.setLocation(p);
pMenu.setVisible(true);
pMenu.requestFocus();
import java.awt.BorderLayout;
import java.awt.TextField;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* http://bbs.csdn.net/topics/390340915
*
* @author ceclinux
*
*/
public class MouseExitExample extends JFrame {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new MouseExitExample();
}
public MouseExitExample() {
setVisible(true);
setSize(300,300);
JButton jb=new JButton("dfsafs");
jb.setSize(200,200);
add(jb,BorderLayout.EAST);
final JTextField tf = new JTextField();
tf.setSize(200,200);
tf.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {