I am using JAVA to simulate a water heater. For a switch I am using buttons, ON, OFF and EXIT. EXIT exits the program, OFF switches the heater off and On switches starts the heating and cooling process.
Basically, I want the heating and cooling process to be an infinite loop until another button is pressed. The problem right now is that when i start the cooling and heating process, the program does not accept any other buttons i press.
How can i break the loop once another button is pressed, no matter where the program is within the loop?
2007-11-03
21:23:15
·
3 answers
·
asked by
airam
2
in
Computers & Internet
➔ Programming & Design
Fieyr ,
That is actually exactly what i did... but once it enters the loop, it will not let me press the off button, so therefore i cannot change the flag
2007-11-03
21:28:35 ·
update #1
I think that the problem with that code is that it stops listening and waits for a change in the flag inside the loop itself.... are there any other ideas??? anyone??
2007-11-03
21:41:31 ·
update #2
For future reference to whoever has this problem:
1) this is not programming 101
2) from what I can gather from other sources threading is the solution together with interuptions.
For further details look at http://java.sun.com/docs/books/tutorial/essential/concurrency/interrupt.html
2007-11-04
07:38:24 ·
update #3