0

I have two questions about Assignment 5. The first one is about the timer. When I add the code for starting the timer, the drawn basket and launcher dissapear. I don't know what I did wrong there. I put a screenshot of my codes in here. enter image description here

The second question is about calling to the methods for moving the basket with the left and right Arrow keys. I have the following code, but it doesn't work:

// calling for the left and right method to move the basket with the left and right arrow keys

if (e == 37) panel.left(); // 37 is the keycode from the left Arrow button

else if (e == 39) panel.right(); // 39 is the keycode from the right Arrow button

Where did I make a mistake?

Share a link to this question (includes your user id)
| edit | | close | delete |
  • @FjodorvanSlooten I now fixed the part of the timer myself, but still the basket will not move. I have used the following codes: in the gameUI: // calling for the left and right method to move the basket with the left and right arrow keys if (e.getKeyCode() == 37) panel.left(); else if (e.getKeyCode() == 39) panel.right(); and in the drawingpanel: // adding the method for moving the basket to the left public void left() { basket.setMoveL(true); basket.move(); } // adding the method for moving the basket to the right public void right() { basket.setMoveL(false); basket.move(); – Inge Mengerink May 18 at 16:16    
  • Add System.out.println() statements to the left() and right() methods. Eg.: System.out.println("left"); and System.out.println("right"); Then Run the App. Do you see the left and right messages in the Console? Otherwise send me the complete Ecplipse folder as a zip-file so I can have a look. – Fjodor van Slooten May 18 at 17:27    
0

Did you do this part of the assignment:?

assignment text

If you did, show us the code of the paintComponent() method. Because that is where all game elements should be drawn.

Your if-statement for checking the key pressed, does not look good:

if (e == 37)

It should use the getKeyCode() method to get the code of the key:

if (e.getKeyCode() == 37)

Just like in the example System.out.println() given in the example code.

Share a link to this answer (includes your user id)
| edit | delete |

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.