KeyStroke with mouse button
hi. i am working on a project that involves w/ keystroke, but i can't get it to work w/ mouse. i wrote a test program for it, but it does not work.can someone please help.
my program:
import javax.swing.KeyStroke;
public class testKeyStroke {
public testKeyStroke()
{
String s = "button1";
System.out.println("s: " + KeyStroke.getKeyStroke(s));
}
public static void main(String[] args)
{
System.out.println("testKeyStroke");
new testKeyStroke();
}
}
the output
testKeyStroke
s: null
Thanks
[605 byte] By [
yaliu07a] at [2007-11-27 10:18:51]

# 1
KeyStroke should be used with valid Keyboard keys not just any string.
For example, when you create a JMenuItem, you can assign a KeyBoard key to fire its associated action when the key is pressed.
JMenuItem item = new JMenuItem("Exit Program");
item.setAccelerator( KeyStroke.getKeyStroke("ctrl W") );
Please read the associated API information about KeyStrokes and post again if you still have a problem or if you manage resolve the problem
ICE
# 2
I don't understand the question?
What is "w/ keystroke" and "w/ mouse"?
Don't forget to use the "Code Formatting Tags",
see http://forum.java.sun.com/help.jspa?sec=formatting,
so the posted code retains its original formatting.
# 3
thanks guys for the reply.
1. if i change the s value
s = "ALT";
then the output will be
testKeyStroke
s: keyCode Alt-P
2. w/ keystroke == with keystroke
w/ mouse == with mouse.
sry about the confusion.
# 4
> thanks guys for the reply.
>
> 1. if i change the s value
> s = "ALT";
>
> then the output will be
> testKeyStroke
> s: keyCode Alt-P
No, the output would be.
s: pressed ALT
System.out.println(KeyStroke.getKeyStroke("ALT"));
output:
pressed ALT