Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

trouble with setMneumonic

807569Aug 19 2006 — edited Aug 22 2006
I want the value of a variable to increment when I press the 0 key on the keyboard. I wrote an application in which I have a button appear on the screen and when I press the button the variable value increments. . I have set mneumonics for that button so that I could do the same thing with the keyboard but it doesn't work. Here are the relevant 9 statements in my code.

protected JButton enlargeWidth
enlargeWidth = new JButton("Enlarge Width");
enlargeWidth.setMnemonic(KeyEvent.VK_0);
enlargeWidth.addActionListener(this);
add(enlargeWidth);

public void actionPerformed(ActionEvent e) {
Object b = e.getSource();
if (b == enlargeWidth){
myVariable += 1;
}
}

Why doesn't this work?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2006
Added on Aug 19 2006
3 comments
52 views