Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

listen if a variable changes



is there a way to listen if a string changes?

for school i have to make a game in java.
my seccond real self made java application ever.

so far so good. its working but i ran into a problem and i cant find an answer anywhere. the following problem

i have a model package and a view package.
the model package contains a class called spel.java

spel.java is the core of the game. it starts the game, it stops the game, it pauses it etc.

starting games and ending them aint the problem. but if the spel.java ends the game it selfs ( you get game over or you win). the stop button in the GUI.java has to change its text to start.

now i want it to do this without using a function in model to launch something from the view package. i want model to be able to stand alone, no GUI needed to run the game.

now in spel.java if the game is active or not can be found in a variable ( a string).

is there some way. i can listen from gui.java if that string changes.
at the moment i fixed it temporarely by adding a timer function with a delay of 1. and repeat set to false. and if 1 of the functions changes the variable it allso starts that timer.. ( a really ugly solution as you can see). any suggestions? thankyou