News:

Tekforums.net - The improved home of Tekforums! :D

Main Menu

Anyone remember java?

Started by addictweb, April 11, 2007, 17:09:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

addictweb

Hey people, im at that point where im in a serius rush to finish my final year project and ive been stuck on something for the past hour.

Ive got a back end program.
Im now writing a GUI for it.

How to I get the program to wait for inputs from the GUI. I cant just put it into a while !ready loop.

Do I HAVE to use threads? I would really prefer to avoid them (i recall them being rather complex).

Basically ive got the main program that calls getDecision() in the GUI and I want that to wait untill on of the buttons actionListeners is fired before it allows the program to continue.

ANY help much appriciated.

Tom
Formerly sexytw

Sam

Add a listener to your button and that will run in a separate thread automatically.

addictweb

Im probably being dim but Im not quite sure what you mean.

Ive got listeners on the buttons, how will having those listeners in a separate thread help me pause the program?

Cheers

Formerly sexytw

madmax

ive no idea on the ins n outs of java,

the wait command is what id normally use on threads in my native tongue and a google search has resulted with this link  :lol:

http://www.janeg.ca/scjp/threads/wait.html

original search
google search

Mardoni

sounds to me like youre mixing your development techniquies; procedural and event driven.

If I were going down the route youre looking at and I wanted to avoid being in a Do:While then I would use a timer interupt based state machine in the backend application. With the GUI using callbacks to trigger a change of state.


addictweb

cheers for the ideas. Ive ended up bodging some kind of threading together with a wait() and notify().

The game logic calls wait()  then the actionListeners call notify() to allow it to continue.

It is a bodge but it seems to work.

Cheers,
Formerly sexytw

Sam

Quote from: sexytwIm probably being dim but Im not quite sure what you mean.

Ive got listeners on the buttons, how will having those listeners in a separate thread help me pause the program?

Cheers


You dont need to, when you open the GUI it automatically runs in its own Thread which will continue to run after your main method finishes. The listeners on the buttons can call methods directly.

Do not prat about with notify and wait, you dont need to go anywhere near it for GUI programming.