trouble with setMneumonic
807569Aug 19 2006 — edited Aug 22 2006I 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?