import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
//练习弹出式菜单
public class Demo10 extends Frame implements MouseListener
{
PopupMenu pop = new PopupMenu();
MenuItem item1 = new MenuItem("黄山");
MenuItem item2 = new MenuItem("庐山");
MenuItem item3 = new MenuItem("泰山");
MenuItem item4 = new MenuItem("华山");
CheckboxMenuItem check1 = new CheckboxMenuItem("长江");
CheckboxMenuItem check2 = new CheckboxMenuItem("黄河");
Demo10()
{
setSize(500,500);
add(pop);
pop.add(item1);
pop.add(item2);
pop.add(item3);
pop.add(item4);
pop.addSeparator();//分割线
pop.add(check1);
pop.add(check2);
this.addMouseListener(this);
setVisible(true);
}
public static void main(String s[])
{
new Demo10();
}
public void mouseClicked(MouseEvent parm1) {
// TODO: Add your code here
if(parm1.getButton()==MouseEvent.BUTTON3)
{
int x = parm1.getX();
int y = parm1.getY();
pop.show(this,x,y);
}
}
public void mousePressed(MouseEvent parm1) {
// TODO: Add your code here
}
public void mouseReleased(MouseEvent parm1) {
// TODO: Add your code here
}
public void mouseEntered(MouseEvent parm1) {
// TODO: Add your code here
}
public void mouseExited(MouseEvent parm1) {
// TODO: Add your code here
}
}
网友评论