This program is only for beginners in Java. Most of you may have imagined it is very difficult of it takes a lot of time to grasp the essence of animation in Java. Well this program here dispels all those fears. It is a very basic (and dare I say an ugly) animation of a red car which moves from left to right.
// CARMOVE.JAVA
// MOVING CAR
// Created by Karthik Sampath on 28/4/2010.
// Copyright 2010, Karthik. All rights reserved.
// The copyright to the computer program(s) herein
// is the property of Karthik Sampath, India. The
// program(s) may be used and/or copied only with the
// written permission of Karthik Sampath or in accordance
// with the terms and conditions stipulated in the
// agreement/contract under which the program(s) have
// been supplied. This copyright notice must not be
// removed.
// Published in www.geekyard.com
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
public class test extends JApplet {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new test());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1024, 739);
frame.setVisible(true);
}
public void paint(Graphics g) {
try {
int j = 0;
while (j < 500) {
g.setColor(Color.white);
g.fillRect(0, 0, 5000, 5000);
g.setColor(Color.red);
g.fillRect(250 + j, 250, 100, 50);
g.setColor(Color.black);
g.fillOval(260 + j, 300, 20, 20);
g.fillOval(320 + j, 300, 20, 20);
j++;
Thread.sleep(2);
}
} catch (InterruptedException e) {
}
}
}
Thanks a lot for sharing this graphics program.
Thanks a lot.. Nice moving car animation in Java 🙂
I found a similar program in C also http://www.techcrashcourse.com/2015/08/c-graphics-program-moving-car-animation.html
Thanks for sharing this to the point and abstract C graphics program to move a car.
Moving car animation in C graphics
pretty cool yar
thats really coooool ……. 🙂
Thank u.
Which IDE you used to generate this java code?
Cheers,
FC
This is cool. Thanks for the share
Nice car move in java. thanks for share