Search:

Type: Posts; User: bgroenks96

Search: Search took 0.07 seconds.

  1. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    I use if/else statements A LOT in Java programming. If you have a better/more advanced way of doing things, PLEASE tell me. You will make my life so much easier.
  2. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    I'm not very familiar with HashMaps so I guess I will just stick with the current code structure in #26.

    I'm using KeyListeners in the main JFrame. I either need a character or keyCode for the...
  3. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    What does that replace in this code to make it more efficient?

    And by the way, do you know how to get the program to register a key event for the ENTER key? I can't get it to respond... it just...
  4. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    If you have a suggestion please let me know. I haven't learned about HashMaps so I... well honestly have no clue what they are.

    I'm not sure how I would put all those conditional statements in an...
  5. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    I think I got it working. I put a keyListener on the mainFrame to the class ListenForKeys and method keyTyped(KeyEven ke)

    It looks like this (and yes I know this is repetitive but it was an easy...
  6. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    Interesting idea with the KeyAccelerator calling the action class.... although I'm not sure if it will work in my program.

    I need to be able to identify the key pressed ahead of time in order to...
  7. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    <Double-Post>
  8. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    Would it maybe be easier to have separate key listeners in the main frame that respond by calling the doClick method on their respective buttons? That would fire the actionPerformed method right?
    ...
  9. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    What if I had key listeners instead of bindings that performed the doClick method on their respective buttons?
  10. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    The program you wrote throws this exception at runtime (it's an Array Index out of bounds):


    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException:
    -1
    at...
  11. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

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

    class KeyTime {
    ArrayList<JButton> buttons;
    JFrame frame;
    JPanel panel;
    JPanel buttonPanel;
  12. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    Sorry double posted there. Didn't even see your posts.... the thread glitched.

    I don't want to frustrate you, but I think I'm missing your point.

    To clarify, I have action listeners for two...
  13. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    Do you mean copy it into my program? Some of those variables don't exist in it... I'm not sure now that would work.

    And I have tried those things. They don't work. I'm pretty sure I need...
  14. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    No doesn't work. I'm pretty sure I need something in the actionPerformed method to process the key event. But I don't know what.

    And do you mean copy it into my current program as is? There is...
  15. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    Here is the class from my code that reads the button actions.



    class ListenForMain extends AbstractAction implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    ...
  16. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    Erm.... Seeing as the amount of code that is in this program involving the ArrayLists I would rather not go back and completely change that unless you REALLY think there is no other way.

    Like I...
  17. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    Ok I read up some on KeyBindings on the API as well as in the Java Tutorials. However, I'm kind of confused on how to use ActionMaps?

    Here is an example from my code:


    for(int...
  18. Replies
    32
    Views
    3,483

    Re: KeyListeners: Automatic Focus?

    I need a way for pressed keys to make the same method (actionPerformed) fire with the correct value.

    Ideally, I want the buttons to actually be "pressed" by the key events.

    I don't know much...
  19. Replies
    32
    Views
    3,483

    KeyListeners: Automatic Focus?

    There are three grids of buttons on my JFrame. Each of those grids has its own JPanel. Right now, the buttons are stored in ArrayLists and each one gets an actionListener and keyListener assigned...
Results 1 to 19 of 19