Re: Press key to exit loop
Unanswerable without more detail.
If this is a console program, it can't be done. Not with a single keypress anyways.
If this is a GUI program you need to tell us what GUI toolkit is used.
db
Re: Press key to exit loop
I'm using AWT and Swing. I think that answers your question.
Re: Press key to exit loop
Then your best bet is to put the executing code into a thread (a Runnable class or Thread class), make it check some variable for quit condition (i.e. boolean isTimeToQuit) then stick a KeyListener (How to Write a Key Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)) on your window to catch the 'Q' press and change isTimeToQuit to true.
Re: Press key to exit loop
I don't know what that means. Runnable class? Thread class? And I don't know how the KeyListener is implemented. Can I get more detail?
Re: Press key to exit loop
I left a link for the KeyListener, as for the Thread and Runnable they are two ways to split your program into two threads and make it do more than one thing simultaneously, it's easy to find info on them online. Just look up multi-threaded programming in Java
Re: Press key to exit loop
Quote:
Originally Posted by
DFTBA
I don't know what that means. Runnable class? Thread class? And I don't know how the KeyListener is implemented. Can I get more detail?
Surely Google is working in your part of the world?
Re: Press key to exit loop
Quote:
Originally Posted by
Fubarable
Surely Google is working in your part of the world?
Google *what*?
kindest regards,
Jos