English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

3 answers

You're going to want to use a class-level boolean flag as well as a while loop.

First initialize the class-level flag as..

priavate boolean heateron = false

Later in the code...BEFORE you enter the loop, your going to want to print a line of code that says "heating/cooling" and set the flag = to true

This code will be within the on button. Right after you output that code, enter the loop.

While(heateron == true)
{


}

The code will be stuck in a loop until you set the heateron variable to false. This code to kick you out of the loop would be in the off button.

Hope that helps.

2007-11-03 21:12:34 · answer #1 · answered by Fieyr 4 · 0 0

This sounded like Programming 101 stuff, so I obviously won't recommend threading as a solution to that, you have to further refine the process into likes of 1% Heating, 2%, 3%... then interjects this infinite loop here with button recognition code.

I say this is Programming 101 because it sounded like the Washing Machine example back then.

2007-11-03 21:36:42 · answer #2 · answered by Andy T 7 · 0 0

a million. detect a .type document. 2. impressive click the .type document to open the context menu. 3. elect "Open With ..." (no longer the lone "Open") 4. contained in the window that seems, the 1st actual you do is tick "consistently use the chosen software to open this way of document" on the backside (so which you do no longer ignore it later). 5. elect Java from the checklist. If java isn't contained in the checklist, then 6. click "Browse ..." and examine to the place the java.exe is. Dependend on which Java Runtime atmosphere you put in it extremely is in distinctive places: Java 6 JRE 32bit: C:software documents (x86)Javajre6binjava.exe Java 7 JRE 32bit: C:software documents (x86)Javajre7binjava.exe Java 6 JRE 64bit: C:software FilesJavajre6binjava.exe Java 7 JRE 64bit: C:software FilesJavajre7binjava.exe which you have have been given have been given a sixty 4 bit OS does no longer unavoidably mean that your Java is sixty 4 bit, too. It thoroughly relies upon on what Java you put in.

2016-09-28 07:22:15 · answer #3 · answered by glassburn 4 · 0 0

fedest.com, questions and answers