Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java png obj animate image size

import java.awt.Image;
import java.util.ArrayList;
/**
 The Animation class manages a series of images (frames) and
 the amount of time to display each frame.
*/
public class Animation {
 private ArrayList frames;
 private int currFrameIndex;
 private long animTime;
 private long totalDuration;
 /**
 Creates a new, empty Animation.
 */
 public Animation() {
 frames = new ArrayList();
 totalDuration = 0;
 start();
 }
 /**
 Adds an image to the animation with the specified
 duration (time to display the image).
 */
 public synchronized void addFrame(Image image,
 long duration)
 {
 totalDuration += duration;
 frames.add(new AnimFrame(image, totalDuration));
 }
 /**
 Starts this animation over from the beginning.
 */
 public synchronized void start() {
 animTime = 0;
 currFrameIndex = 0;
 }
 /**
 Updates this animation's current image (frame), if
 necessary.
 */
 public synchronized void update(long elapsedTime) {
 if (frames.size() > 1) {
 animTime += elapsedTime;
 if (animTime >= totalDuration) {
 animTime = animTime % totalDuration;
 currFrameIndex = 0;
 }
 while (animTime > getFrame(currFrameIndex).endTime) {
 currFrameIndex++;
 }
 }
 }
 /**
 Gets this Animation's current image. Returns null if this
 animation has no images.
 */
 public synchronized Image getImage() {
 if (frames.size() == 0) {
 return null;
 }
 else {
 return getFrame(currFrameIndex).image;
 }
 }
 private AnimFrame getFrame(int i) {
 return (AnimFrame)frames.get(i);
 }
 private class AnimFrame {
 Image image;
 long endTime;
 public AnimFrame(Image image, long endTime) {
 this.image = image;
 this.endTime = endTime;
 }
 }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to make a string alphabetic 
Java :: how to use old android studio project 
Java :: List Double, fixed size 
Java :: java see you next happy year 
Java :: arrays in constructor java 
Java :: dynamic fib 
Java :: how to see page is open in selenium 
Java :: math ceil java 
Java :: licenceurl 
Java :: how to find length of string array java 
Java :: aspectj after returning 
Java :: Java Another form of assertion statement 
Java :: retrofit interface 
Java :: mostrar divisores java 
Java :: super class and concrete class in java 
Java :: site:stackoverflow.com List is abstract; cannot be instantiated public List<Integer result = new List<(); 
Java :: how to implement count steps in android 
Java :: api to accept a csv file spring boot 
Java :: In similar fashion we will use (RIGHT – SHIFT) to retrieve bits from val 6 at a time 
Java :: dynamically create textview and add it in linearlayout in recyclerview adapter android 
Java :: handle customized popup in selenium 
Java :: how to write to a txt file in java in the end 
Java :: java assert keyword 
Java :: What is the name of the Android function that is used to update the UI (user interface) from a background thread? 
Java :: spring boot endpoint getting list from the body 
Java :: on offline event spigot example 
Java :: expiry time of otp android 
Java :: declare a variable java 
Java :: edit xmlns attribute with jaxb marshaller 
Java :: public class HelloWorld { public static void main( String[] argv ) { int a=4%2*3-1/0; System.out.println(a); } } 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =