Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Animating Images in Java Application

                         

This section shows you how to create an animation with multiple images. You can see how animation has been implemented in the following program or example. The given program implements the animation using more than one images. Image are given below:

First image of swing animation

Second image of swing animation

In this program, images are displayed one by one from the list of the images. Images are added to the label on the frame or window. This program shows the image one by one after 1000 milliseconds or 1 second. The time delaying is maintained by thread. 

Code Description:

One method has been used to show images on the frame one by one during the 1000 milliseconds. This collection of images makes the application as an animation.

sleep(int time):
This is the method of the Thread class which is used to sleep the program for the specified time. The time to sleep is passed through the
sleep() method of the Thread class as parameter.

Here is the code of the program:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SwingAnimation{
  Thread th;
  ImageIcon images;
  JFrame frame;
  JLabel lbl;
  int i = 0;
  int j;

  public static void main(String[] args){
    SwingAnimation sa = new SwingAnimation();
  }

  public SwingAnimation(){
    frame = new JFrame("Animation Frame");
    th = new Thread();
    lbl = new JLabel();
    Panel panel = new Panel();
    panel.add(lbl);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(400400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    for(j = 1; j <= 2; j++){
      SwingAnimator();
      if (j == 2)
        j = 0;
    }
  }

  public void SwingAnimator(){
    try{
      for(i = 1; i <= 5; i++){
        images = new ImageIcon("images/img" + i + ".gif");
        lbl.setIcon(images);
        th.sleep(1000);
      }
    }
    catch(InterruptedException e){}
  }
}

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

dear sir,
how to create games and music by using java

Posted by faizal on Saturday, 12.8.07 @ 14:25pm | #41589

Latest Searches:
insert() method in Tex
javacodetodividewindow
present
Write a program that d
Combattons la programm
PhotoshopDrawingMerced
get character in java
hibernate basics
JSp:Input Parameter
panel group
floating point
displaying text in a d
java random numbers
assertNull
request.setAttribute(H
get character array in
update and delete from
delete data to text fi
Math.random()
javastring
TCP buffer
Create a Scroll Pane C
get column count colu
Array in Java
Ajax Examples
hibernate from clause
save query string
harePoint Designer
sort object compareTo
list iteration in java
display messagebox in
builb.xml
Request Object In JSP
input values from cmd
ASP EXAMPLE and 1=2
two tables insertion
java display applet me
questions in Jboss
exception handiling
guid
advantages of jsf
ASP EXAMPLE
JAXB
3DS MAX Modeling Barre
login form in swing
b tree implementation
ziiping a folder
JSP:Input type file
sum of rows and coloum
scheduler inmysql
how to run java file i
redirecting
Lucene in Action
UPDATE QUERY JAVA
Socket tcp
date function java scr
select a row in jsp
JSP:File Browse
Photoshop Candy Cane E
Submit comments in dat
string operations
jfreechart
value change listener
show folder contents
time command in java
using check box in dat
ajax
Photoshop Cut out imag
stopwacth
Jmenu in java
JSLT Example
java keyword
netbens jsf
string variable
events in jsp
JSP:File Field
Netbeans JSF
changehashtablevalue
<select><option> jsp d
DefaultMutableTreeNode
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.