mnemonic keys only work after mouse used
Hi
I have only just noticed that my mnemonic keys do not work as soon as the applet is started. It appears that I have to click on one of the buttons with the mouse and then once this happens the mnemonic keys start working.
Can anyone help? :SICK:
some of my code for one button is below:
Code:
public class BinaryTreeDisplay extends JApplet implements ActionListener, WindowListener, AdjustmentListener {
// Start Search button
startButton = new javax.swing.JButton();
startButton.addActionListener(this);
startButton.setBackground(buttonColour);
startButton.setFont(new java.awt.Font("MS Sans Serif", 1, 16));
startButton.setForeground(buttonFontColour);
startButton.setMnemonic(KeyEvent.VK_S);
startButton.setToolTipText("Start search");
startButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
startButton.setText("START SEARCH");
startButton.setPreferredSize(new java.awt.Dimension(157, 25));
gamePanel.add(startButton);
public void actionPerformed(ActionEvent e) {
if (e.getSource() == startButton){ // START SEARCH/NEW SEARCH BUTTON is clicked
btd.generateTree(); // call generateTree method from BinaryTreeAction to setup tree ready for paint
notFoundButton.setEnabled(true);
foundButton.setEnabled(true);
if (btd.torch.getLeft() != null) // if there is a left node
downLeft.setEnabled(true); // then enable to the move down left button
else if (btd.torch.getLeft() == null) // if there is no left node
downLeft.setEnabled(false); // then disable the move down left button
if (btd.torch.getRight() != null) // if there is a right node
downRight.setEnabled(true); // then enable the move down right button
else if (btd.torch.getRight() == null) // if there is not a right node
downRight.setEnabled(false); // then disable the move down right button
viewAllButton.setEnabled(true);
updateImage(); // display Binary Search Display onto buffered image
questionTextPanel.setText("Is node " + btd.question + (" in the tree?")); // update the question field with which node to search for
startButton.setText("NEW SEARCH"); // change label of button to new search
startButton.setToolTipText("New search"); // change mouse hover tool tip
btd.resetVariables(); // call method to reset variables for new search
repaint();
Can anyone help me with this?
I have read before about focus, is it that I need to pass focus to something? how would I do this?
thanks very much :D