mnemonic keys only work after mouse used


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: mnemonic keys only work after mouse used

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Posts
    32

    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?

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Issue a requestFocus() for the container (applet) after initiation
    eschew obfuscation

  3. #3
    Join Date
    Jul 2005
    Posts
    32
    Thanks for the response, will try doing this later

Similar Threads

  1. Replies: 0
    Last Post: 10-15-2001, 08:52 PM
  2. Mouse Movement Playback
    By Eugene in forum VB Classic
    Replies: 4
    Last Post: 12-19-2000, 01:52 PM
  3. Mouse Position
    By Ranger in forum VB Classic
    Replies: 0
    Last Post: 12-07-2000, 02:23 PM
  4. Justification for tele-commuting
    By Jason Langston in forum Careers
    Replies: 10
    Last Post: 08-08-2000, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center