The program freezes because I put a loop in the action listener for the grandma button.I know why it won\'t work, but I can\'t seem to find a way around it. Can anyone tell me a
In this program, there is a cookie button that works, and a grandma button that should trigger a while loop, that will add a cookie every 5 seconds.::
Don't use a loop in the ActionListener. The loop blocks the Event Dispatch Thread and prevents the GUI from repainting itself.
Instead you should be using a Swing Timer
Read the sections from the Swing Tutorial on:
Concurrency in Swing
How to Use Timers
for more information.
Also, variable names should NOT start with an upper case character. Sometimes your names are correct and sometimes they are not. Be consistent!!!
And get rid of all that blank space. Use proper formatting if you want to post code for people to read. Right now the posted code is a mess to read.