哪位老师能帮帮我?
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
class PopupMenuTest extends JPanel
{
static JFrame frame1;
JLabel l1;
JPopupMenu popupMenu;
public PopupMenuTest()
{
l1=new JLabel("单击鼠标右键");
popupMenu=new JPopupMenu();
JMenuItem menu1=new JMenuItem("橘子");
JMenuItem menu2=new JMenuItem("菠萝");
JMenuItem menu3=new JMenuItem("芒果");
menu1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
l1.setText("橘子");
}
});
menu2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
l1.setText("菠萝");
}
});
menu3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
l1.setText("芒果");
}
});
popupMenu.add(menu1);
popupMenu.add(menu2);
popupMenu.add(menu3);
addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
{
popupMenu.show(e.getComponent(),e.getX(),e.getY());
}
}
});
add(l1);
}
public static void main(String [] args)
{
frame1=new JFrame("弹出菜单测试");
PopupMenuTest p1=new PopupMenuTest();
frame1.getContentPane().add("Center",p1);
frame1.getContentPane().setBackground(Color.gray);
frame1.setSize(200,200);
frame1.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame1.show();
}
}
这段代码中哪段代码具有实现单击鼠标右键弹出菜单的功能啊