That does not make any sense.
Change the code to print out the message when a car has completed a lap.
BTW How much of the code you posted for this program did you write? You don't seem to...
Type: Posts; User: Norm
That does not make any sense.
Change the code to print out the message when a car has completed a lap.
BTW How much of the code you posted for this program did you write? You don't seem to...
Where are the messages for the other two cars?
When does your code print out the "completed" message?
It looks like it could work. What happens when you compile and execute the program?
Yes, that is how I would do it.
No, do the increment outside of the println in its own statement.
A sample of printing:
int laps = 3; // for testing only
System.out.println("Car laps=" +...
Your last post looks just like the broken code you posted earlier.
Lets start with a simple problem and change it as you go along.
Take the code that has the three cars running the race. Change...
What test do you make with the if statement to determine if the counter should be incremented?
Where is this counter's value incremented?
Yes you will use a counter.
Will there be a counter for each car?
Where will you increment the counter?
How will you know that all the cards are stopped?
You need lots more details on how...
Ok, how are you going to keep track of each car's number of laps?
And how are you going to know when all three cars have finished their three laps?
What do you want to do as they each restart the next lap?
Should there be a counter for each car?
Should the race stop when ONE car has completed the number of laps?
I suggest that you remove the code that is now using the count variable and get the three cars to move.
Then think about what you want to do when they each restart the next lap.
Why do you only start the thread when the count is > 3?
Where is the value of count changed relative to the calls to the run method?
Is run() called more than once?
Does your code do that? What are the steps you need to do to do that?
Here is your code, slightly modified:
if(count <= 3) {
t1 = new Timer((int)s1, new ActionListener() {...
I've just looked more closely at your code.
I have no idea what the code is trying to do. There are no comments describing what you want it to do.
For example, what are these statements supposed to...
If you can make it go for 2 laps, it should be easy to continue going for the third lap.
What happens after it goes for the first two laps?
Go to the API doc for javax.swing.Timer.
There are links there to the tutorial which has examples of how to use the Timer class.
You need to concentrate on the animation part only. The rest of your code would be in the way.
Start with using a Swing Timer to change the x,y positions of the images and then call repaint() to...
Search on this forum or google for example codes
I think it might be useful for you in learning how to animate your program to look at one of the many bouncing ball programs that exist. Search on this forum or google for example codes that will...
How are you changing the x,y positions of the cars as they move?
How are you defining the x,y positions of the curves
You'll some things for the cars to move.
The first would be a timer that will change their x,y position every small unit of time.
The second would be a definition of where the track is. This will...
Your program must have the path to where the image files are located on your computer.
You can use relative paths such as: images/<theImage>
Either move the images or change the name of the...
Your code has: " images/Track.gif"
the image file location: C:\Users\Daniel\Pictures>
These are not the same!!! They must be the same.
In the command prompt window use the cd command to change directories.
Here is a sample of its usage:
D:\JavaDevelopment\Testing>cd ..
D:\JavaDevelopment>cd Testing
...
That's part one. Where is this part?
Open a command prompt window, change to the folder with the images and enter the command: dir
Copy and paste the contents here:
To copy the contents of the...
To show me, Copy the few lines of code from your program that load the images and that show the file names and paste them here
Open a command prompt window, change to the folder with the images and...