R
Richard A. DeVenezia
How do I respond to menu selections ?
I have FigurePanel, which is a subclass of JPanel. The constructor calls
init() which is
public class FigurePanel extends javax.swing.JPanel implements
java.io.Serializable, MouseListener, MouseMotionListener {
/*stuff*/
JPopupMenu cutMenu;
void init (double llx, double lly, double urx, double ury) {
/*stuff*/
cutMenu = new JPopupMenu();
cutMenu.add(new JMenuItem("Cut"));
cutMenu.add(new JMenuItem("Cancel"));
}
public void mouseClicked(MouseEvent e) {
/*stuff*/
cutMenu.show(e.getComponent(),e.getX(),e.getY());
/*stuff*/
}
The menu appears and I can select Cut or Cancel or click somewhere off the
menu and the menu goes away.
I don't know how to have my panel respond to
Cut selected
Cancel selected
Menu lost focus (do same thing as Cancel)
.....
I tried
cutMenu.add(new JMenuItem("Cut")).addActionListener(thsi);
but the compiler barked
addActionListener(java.awt.event.ActionListener) in
javax.swing.AbstractButton cannot be applied to (FigurePanel)
I would love to be able to simply do
JMenuItem selected = cutMenu.show(e.getComponent(),e.getX(),e.getY());
but that is not in the cards.
Thanks
I have FigurePanel, which is a subclass of JPanel. The constructor calls
init() which is
public class FigurePanel extends javax.swing.JPanel implements
java.io.Serializable, MouseListener, MouseMotionListener {
/*stuff*/
JPopupMenu cutMenu;
void init (double llx, double lly, double urx, double ury) {
/*stuff*/
cutMenu = new JPopupMenu();
cutMenu.add(new JMenuItem("Cut"));
cutMenu.add(new JMenuItem("Cancel"));
}
public void mouseClicked(MouseEvent e) {
/*stuff*/
cutMenu.show(e.getComponent(),e.getX(),e.getY());
/*stuff*/
}
The menu appears and I can select Cut or Cancel or click somewhere off the
menu and the menu goes away.
I don't know how to have my panel respond to
Cut selected
Cancel selected
Menu lost focus (do same thing as Cancel)
.....
I tried
cutMenu.add(new JMenuItem("Cut")).addActionListener(thsi);
but the compiler barked
addActionListener(java.awt.event.ActionListener) in
javax.swing.AbstractButton cannot be applied to (FigurePanel)
I would love to be able to simply do
JMenuItem selected = cutMenu.show(e.getComponent(),e.getX(),e.getY());
but that is not in the cards.
Thanks