?
=?ISO-8859-1?Q?St=E9phane_St-Pierre?=
HI, I'd like to create a Class that would give me JMenuItem generated
with specific
parameters,like the name and - specially, the Key Accelerator. My
problem is that I just can't pass
any int value to the getKeyStroke(ke, ev) method, event with the
appropriate import. How can I use the VK_C "constant" and pass it to
the method ? I figure a sad one : (int)'C' but it ain't secure and
it's ugly.
What I want to do is to call my constructor with :
new JSMenu(menuEdition, KeyEvent.VK_C, META_MASK);
import javax.swing.event.MenuKeyEvent.*;
import java.awt.event.KeyEvent.*;
final JSMenu smenuCut = new JSMenu(menuEdition, "Cut", (int)'C', 4);
//================================================================================
//class JSousMenu
final class JSMenu extends JMenuItem
{
public JSMenu(JMenu menu, String sMenu, int ke, int ev)
{
super(sMenu);
this.setAccelerator(KeyStroke.getKeyStroke(ke, ev));
this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}});
menu.add(this);
}
}
with specific
parameters,like the name and - specially, the Key Accelerator. My
problem is that I just can't pass
any int value to the getKeyStroke(ke, ev) method, event with the
appropriate import. How can I use the VK_C "constant" and pass it to
the method ? I figure a sad one : (int)'C' but it ain't secure and
it's ugly.
What I want to do is to call my constructor with :
new JSMenu(menuEdition, KeyEvent.VK_C, META_MASK);
import javax.swing.event.MenuKeyEvent.*;
import java.awt.event.KeyEvent.*;
final JSMenu smenuCut = new JSMenu(menuEdition, "Cut", (int)'C', 4);
//================================================================================
//class JSousMenu
final class JSMenu extends JMenuItem
{
public JSMenu(JMenu menu, String sMenu, int ke, int ev)
{
super(sMenu);
this.setAccelerator(KeyStroke.getKeyStroke(ke, ev));
this.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}});
menu.add(this);
}
}