Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > KeyStroke madness

Reply
Thread Tools

KeyStroke madness

 
 
=?ISO-8859-1?Q?St=E9phane_St-Pierre?=
Guest
Posts: n/a
 
      09-19-2003
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);
}
}
 
Reply With Quote
 
 
 
 
Gerbrand van Dieijen
Guest
Posts: n/a
 
      09-19-2003
On 19 Sep 2003 14:47:10 -0700, Stéphane St-Pierre wrote:
>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.
>


You can use the Action and AbstractAction and KeyStroke object for that.

It's slightly more complicated to use, but supports all things to
programmatically create menu files from (for example) resource files.

I've created a class with methods that do similar things like what you're
writing, if your interested I can mail it (free of course).

--
Gerbrand van Dieijen

WWW: http://twisted.warande.net
ICQ: 19345450



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keystroke saving w/ IEEE.Numeric_Std JustJohn VHDL 6 03-29-2006 05:21 PM
Madness, I call it madness Marius Horak ASP .Net Datagrid Control 2 06-04-2004 02:28 PM
Capture keystroke Brian Simpson Java 1 01-22-2004 03:33 PM
Keystroke Count Herb Stull ASP .Net 4 10-22-2003 07:33 PM
Which keystroke do you press for the OR logical operator? Fred Java 6 08-02-2003 11:34 AM



Advertisments