Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 4:47 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: create Animation in java
PostPosted: Tue Nov 11, 2008 5:53 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

create Animation in 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)

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 video chat application in java
 navigating to database using java
 java mobile apps
 need help in java
 Read your gmail using Java code
 Java Programing to communicating port parallel
 Java Chat
 Steganography in java
 java code for listing folder contents from remote folder
 java

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: Google Adsense [Bot] and 2 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team