PopUpTest(LAB 6-2)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class PopUpTest extends JFrame{
JPopupMenu pop=new JPopupMenu();
JMenuItem open=new JMenuItem("Open");
JMenuItem copy=new JMenuItem("Copy");
JMenuItem cut=new JMenuItem("Cut");
JMenuItem paste=new JMenuItem("Paste");
JMenuItem exit=new JMenuItem("Exit");
PopUpTest(){
setSize(400,300);
setTitle("Pop-Up Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pop.add(open);
pop.add(copy);
pop.add(cut);
pop.add(paste);
pop.add(exit);
JPanel p=new JPanel();
p.setComponentPopupMenu(pop);
p.addMouseListener(new MouseAdapter(){});
getContentPane().add(p);
setVisible(true);
}
public static void main(String[]args){
new PopUpTest();
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น