Search:

Type: Posts; User: Norm

Search: Search took 0.13 seconds.

  1. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    Glad you got it working.
  2. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    Is the key listener method called? Add a println() to see.
  3. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    The code works for me.
  4. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    New images should NOT be loaded in the paintComponent() method. Load the image outside of that method and then call repaint() to have the system call the paintComponent() method where the newly...
  5. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    Change a and call repaint().
  6. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    Set a to the first image in the constructor so its value is not null when paintComponent() is called.
  7. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    You don't control when the system calls the paint methods. The repaint() method requests that a call be made some time (usually soon).
    What do you want to see on the screen BEFORE the user presses...
  8. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    The test for a being null would be in the paintComponent() method.

    You can't change the order of when the methods are executed. The user's key pressed can't be recognized before the screen is...
  9. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    The paintComponent() method is called BEFORE the user gets a chance to press any keys. Add code there to test if a is null before using the value in a.
  10. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    There is a null value when line 48 is executed. Look at line 48, find the null value and then backtrack in the code to see where the null value came from.
  11. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    When you have errors, you should copy the full text of the message and paste it here.
  12. Replies
    28
    Views
    3,017

    [SOLVED] Re: How to change image when a key is pressed?

    @jocdrew21 Please edit the code in your post and give it proper formatting. Nested statements should be indented.

    @jerinjose61 Please edit your post and wrap your code with code tags:


    YOUR...
Results 1 to 12 of 12