It is very interesting java program using java awt. Here is the program code to create popup menu when your press right mouse button.
import javax.swing.*;
import java.awt.event.*;
public class PopUpMenu{
JPopupMenu Pmenu;
JMenuItem menuItem;
public static void main(String[] args) {
PopUpMenu p = new PopUpMenu();
}
public PopUpMenu(){
JFrame frame = new JFrame("Popup Menu Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Pmenu = new JPopupMenu();
menuItem = new JMenuItem("New");
Pmenu.add(menuItem);
menuItem = new JMenuItem("Open");
Pmenu.add(menuItem);
menuItem = new JMenuItem("Save");
Pmenu.add(menuItem);
menuItem = new JMenuItem("Cut");
Pmenu.add(menuItem);
menuItem = new JMenuItem("Paste");
Pmenu.add(menuItem);
menuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){}
});
frame.addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent Me){
if(Me.isPopupTrigger()){
Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
}
}
});
frame.setSize(400,400);
frame.setVisible(true);
}
Tuesday, January 8, 2008
Subscribe to:
Posts (Atom)