Basically, i'm trying to make a basic traffic simulator, and learn java at the same time, so bare with me...
I want a couple of threads to run concurrently in the applet, but am having touble. Basically one starts inside the run() and works fine, but the other wont...infact nothing after the first thread will run (i.e. if the repaint() goes after the end of catch{}). The source is a bit of a mess with no comments, but its all really basic so should be easy for even the elementary java programmer to understand.
I know the second thread (well what i hope is a second thread) doesn't actually do anything other than output a line that could be done by the first thread, but its just proof of concept for now, i will put stuff in there later.
source, class and html are here:
http://www.soton.ac.uk/~tr403/traff/
also the slider in the bottom right doesn't appear in the browser unless you click on it, but in the applet viewer it comes up...why is this? its at the bottom of my priorities at the mo, but its puzzling, and obviously something really elementary.
Any help MUCH appreciated, its for my dissertation which has got be to handed in on may 11th ;)
This the run bit, initated from the start [method? not sure on terminology yet]
public void run()
{
Thread carmove = Thread.currentThread();
try {
while (carmove != null){
Thread.currentThread().sleep(carsptimeout);
xcount++;
repaint(0,144,300,5);
if (xcount == maxlength1){
xcount = 0;
}
}
}
catch (InterruptedException e){}
Thread sysline = Thread.currentThread();
try {
while (sysline != null){
Thread.currentThread().sleep(carsptimeout);
System.out.println(xcount);
}
}
catch (InterruptedException e){}
}
public void stateChanged(ChangeEvent e)
{
tempreadout.setText
(" " + (slider.getValue()));
carsptimeout = 100 - (int)slider.getValue();
}
public void update(Graphics g)
{
paint(g);
}