Whye does my Thread.wait() method apply to the whole program
I have GUI application that I want control with buttons. when I press one button(start) I want to execute one methode that calculates some numbers and prints out the result. Since there are severeal result I want the method to wait after the first answer, and I when i press my other button(continue) I want the method to continue and show me the next answer.
My problem is when I press the start button and get to the wait() method the whole application just freeze. The whole app seems to wait. I have tested with wait(some miliseconds) and the case is same. The whole app waits for some seconds and then continues. The clue is that i dont want the whole app to wait, only the method that prints out.
Here is the thread class. The only one in the code.
I also have a class that extends JFrame to build up the GUI. In that class I have a inne actionlistener class where I listen when the buttons are clicked.
When the button start is clicked it calls a method that gets a user input and sends it to the testNumber method. When the method is called it should stopp after the wait(); When I then press my other button it should continue. The continue button has only a notify() method.
import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.awt.*;
import java.awt.event.*;
import easyIO.*;
import java.util.*;
class Ruteextends Thread
{
Rute()
{
}
synchronizedvoid testNumber(int radNr,int kolNr)
{
int nesteRad = radNr;
int nesteKol = kolNr;
nesteKol++;
if (nesteKol == brettSt鴕relse)
{
nesteKol = 0;
nesteRad++;
}
if (brett[radNr][kolNr] == 0)
{
for (int n=1; n<=brettSt鴕relse; n++)
{
if (gyldigTall(n,radNr,kolNr,brett))
{
brett[radNr][kolNr] = n;//legger inn verdier i brettet.
if (sisteRute(radNr, kolNr))
{
tegnBrett(brett);
l鴖ninger++;
}
else
{
testAlleSiffer(nesteRad, nesteKol);
}
brett[radNr][kolNr] = 0;
}
}
}
else
{
if (something)
{
System.out.println("Wait after this ");
try
{
//Thread.sleep(1*1000);
wait();//When it comes here the whole app waits
notify();
}
catch(InterruptedException e)
{
System.out.println("Du fikk en wait feil: " + e);
}
}
else
{
doSomethingElse();
}
}
}

