Use a listener.
Type: Posts; User: Norm
Change the values of x and y as the window is resized,
The game could adjust it self to the size of the window. It shouldn't have hardcoded values for the location of the boundaries.
Can you use the boundary of the window where the snake is moving? For example locations 0 and width or height?
Same response. Please explain what you are trying to do.
That's not now actionlisteners work. They are for handling user actions like when a button is pressed.
What problems are you trying to solve with the action listener
and with the rectangle?
This would be one place to print out the variables:
What variables are hitting the boundaries? Where and how should the boundary be detected?
Try debugging your code by adding println() statements to show execution progress and how variable values are changing. For example:
Add a: System.out.println("var=" + var);
after every line where...