Author Topic: Anyone remember java?  (Read 1409 times)

Anyone remember java?
on: April 11, 2007, 17:09:46 PM
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

  • Offline Sam

  • Posts: 3,943
  • Hero Member
Anyone remember java?
Reply #1 on: April 11, 2007, 19:03:33 PM
Add a listener to your button and that will run in a separate thread automatically.

Re:Anyone remember java?
Reply #2 on: April 11, 2007, 19:17:55 PM
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

  • Offline madmax

  • Posts: 782
  • Hero Member
Re:Anyone remember java?
Reply #3 on: April 11, 2007, 21:10:10 PM
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

  • Offline Mardoni

  • Posts: 2,636
  • Global Moderator
  • Hero Member
  • On the Sofa, probably ;)
Anyone remember java?
Reply #4 on: April 13, 2007, 11:06:46 AM
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.


Anyone remember java?
Reply #5 on: April 14, 2007, 15:42:12 PM
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

  • Offline Sam

  • Posts: 3,943
  • Hero Member
Re:Anyone remember java?
Reply #6 on: April 14, 2007, 18:03:55 PM
Quote from: sexytw
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



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.

0 Members and 1 Guest are viewing this topic.