Search:

Type: Posts; User: Norm

Search: Search took 0.10 seconds.

  1. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    Post #26 has over 26 if/else if and assignment statements.
    You can replace ALL of them with the one statement in post #29
    However you have to load the HashMap so its not that much less code.
    ...
  2. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    Give HashMaps a key and they return a value associated with that key.


    ...
    } else if(key.equals("3")) {
    JButton b = mainButtonList.get(8);
    ...

    vs
  3. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    With repeating code like you have, there must be a way to put all that in an array or a HashMap.
  4. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    Before when?
    Are you looking at my post #22?
  5. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    Here's another version:


    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;

    @SuppressWarnings("serial")
  6. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    Ok. There were no comments in the code, so all I could do was have the key press go to the action listener. I didn't know what to do then. The listener needs to recognize how it was called (button...
  7. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    How is it supposed to work? What key presses are supposed to do what?

    Here's my version that will react when the 'a' key is pressed.


    import javax.swing.*;
    import java.awt.*;
    import...
  8. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    If you use key bindings you may be able to bind the key events to the container that all the components are in.

    The key binding's actionPerformed method could call the actionPerformed method used...
  9. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    I thought that player1 was the only one. The add(player1); line should be commented out as are the ones underneath it.

    The "this" refers to the JPanel that the code is in.
  10. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    Sorry, there are so many ways for a program to "not work" that I have no idea what the problem is.

    Sorry, I meant to say: Replace "player1" with a component in your code that is being displayed.
  11. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    What I posted was for a quick and easy demo. I was hoping that you could copy and paste it as is.
    Then test it by executing your code and pressing Ctrl-Z or the Y and have a message printed.
    Did...
  12. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    I don't see what bearing the use of ArrayLists to hold references makes to whether you use key listeners vs key binding.

    I guess repetative code would have been a better way to say it.

    Here's a...
  13. Replies
    32
    Views
    3,486

    Re: KeyListeners: Automatic Focus?

    A suggestion on your code. When I see regular code like you have I think array. Put the text for the buttons in an array in the order you want to index them:
    String[] btnTexts = new String[] {"7",...
Results 1 to 13 of 13