본문 바로가기

개발하자/JAVA중급

awt PopupMenu

import java.awt.*;
import java.awt.event.*;

class A{
  public static void main(String args[]){
    Frame f=new Frame();
  f.setBounds(200,200,600,400);
  f.setVisible(true);


  PopupMenu pm=new PopupMenu();
  pm.add(new MenuItem("메뉴1"));
  pm.add(new MenuItem("메뉴2"));
  f.add(pm);


  f.addMouseListener(

   new MouseAdapter(){
    public void mouseClicked(MouseEvent e){
     if(e.getButton()==MouseEvent.BUTTON3)
      pm.show(f,e.getX(),e.getY());
    }
   }

  );
  
  }
}