Total members 11895 |It is currently Sun Dec 22, 2024 8:08 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





create Animation in java
java code
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;

public class CreateAnimation extends JFrame {
private static int DELAY = 90;
Insets insets;

Color colors[] = { Color.PINK, Color.YELLOW, Color.GREEN, Color.RED,
Color.BLUE, Color.CYAN };

public void paint(Graphics graphics) {
super.paint(graphics);
if (insets == null) {
insets = getInsets();
}
int steps=colors.length;
int x = insets.left;
int y = insets.top;
int width = getWidth() - insets.left - insets.right;
int height = getHeight() - insets.top - insets.bottom;

synchronized (colors) {
for (int i = 0; i < steps; i++) {
graphics.setColor(colors[i]);
graphics.fillRect(x, y, width, height);
}
}
}
public void go() {
TimerTask timerTask = new TimerTask() {
public void run() {
Color color = colors[0];
synchronized (colors) {
System.arraycopy(colors, 1, colors, 0, colors.length - 1);
colors[colors.length - 1] = color;
}
repaint();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 0, DELAY);
}
public static void main(String args[]) {
CreateAnimation animation = new CreateAnimation();
animation.setSize(250, 200);
animation.show();
animation.go();
}
}


i hope you like it , 8)



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : create Animation in java
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 Create a Custom Log in java     -  
 Create set up file of my java application     -  
 create Sparse Matrix in java     -  
 Create a firewall project in java     -  
 How to create Email from Core Java Code     -  
 How to create a file in java script using FireFox     -  
 how to create a photo management system using java     -  
 Simple animation     -  
 Sprite Animation     -  



Topic Tags

Java Graphics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com