该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.*;
import java.awt.event.*;
public class demoPupUp extends Frame implements ActionListener
{
TextArea tObj;
PopupMenu popM;
MenuItem miObj1_1, miObj1_2, miObj1_3;
public demoPupUp()
{
popM=new PopupMenu();
miObj1_1=new MenuItem("?甆, new MenuShortcut(KeyEvent.VK_O));
miObj1_2=new MenuItem("?㡢, new MenuShortcut(KeyEvent.VK_P));
miObj1_3=new MenuItem("͋??new MenuShortcut(KeyEvent.VK_E));
popM.add(miObj1_1);
popM.add(miObj1_2);
popM.add(miObj1_3);
miObj1_3.addActionListener(this);
tObj=new TextArea();
tObj.setBackground(Color.PINK);
tObj.add(popM);
tObj.addMouseListener(new MouseAdapter(){
public void mouseRelease(MouseEvent e)
{
if(e.isPopupTrigger())
{
popM.show((Component)e.getSource(), e.getX(), e.getY());
}
}
public void mousePressed(MouseEvent e)
{
//popM.show((Component)e.getSource(), e.getX(), e.getY());
if(e.isPopupTrigger())
{
//这里到达不了, 上面的方法总是返回false,为啥?
popM.show((Component)e.getSource(), e.getX(), e.getY());
}
}
});
add(tObj);
tObj.setVisible(true);
setSize(400, 300); setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
dispose();
System.exit(0);
}
public static void main(String s[])
{
new demoPupUp();
}
}