Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle state machine

Status
Not open for further replies.

qvtqt

Programmer
Oct 13, 2000
16
0
0
US
I'm creating a state machine that depends on a GUI event to change from one state to the next. For example,
state A (current state)
|
|
(mouse click)
|
|
state B (future state)

The problem is I don't know how to the object representing "state A" to sit and wait for an event generated by another thread. How does that gets done?

Thanks.
 
There are a lot of ways to implement what you want to do. You can add a mouselistener to your component and when the mouse is clicked, call it to change to stateB.

Perhaps you can say out what you are trying to do so that it is possible to analyse and get the best solution for implmenting it.

Regards,
Leon
 
I know the way I wanted to implement state is not a good way, but I'm still curious as to how to implement:
independent threads interacting with each others

For example, I would like to create 3 pins in a pin-ball machine that dynamically interacts with each others. I would run those 3 objects as threads. As the ball bounces off from one pin to the next, how do I notify the receiving pin that a ball is coming its way? The problem is that once a thread is running, how does it receive external inputs? It seems like Java doesn't allow a running thread to be called from another thread. Am I wrong on this?

qt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top