Animation in Applets

Animation in Applets

Hello sir,
I have a code for you .this code is for moving a plane in an applet,but unfortunatly
this code is not working .can you kindly help me out to solve this problem.

code:


import java.applet.*;
import java.awt.*;
import java.net.*;
/*<applet code="Moveplane.class" height=600 width=800>
</applet>
*/
public class Moveplane extends Applet
{
public void paint(Graphics g)
{
Font f=new Font("Arial",Font.BOLD,30);
g.setFont(f);
g.setColor(Color.green);
g.drawString("Telangana AirLines",300,35);

try
{
Image i1=getImage(getDocumentBase(),"a1.gif");
g.drawImage(i1,50,50,null);

Thread.sleep(100);
}
catch(Exception e){}
for(int s1=7,s2=70; s1<6100||s2<3000;)
{

if(s1<610)
s1=s1+9;
if(s2<300)
s2=s1+20;
try
{
Thread.sleep(100);
}
catch(Exception e){}

}
}
}
View Answers

March 25, 2010 at 5:40 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.applet.*;
import javax.imageio.*;
import java.awt.event.*;
import java.awt.image.*;

public class Moveplane extends Applet implements Runnable{
Vector <Move> vector;
java.util.List<BufferedImage> images = new ArrayList<BufferedImage>();
BufferedImage buffImage;
Thread thread;
boolean animating = false;

public void init() {
loadImages();
vector = new Vector<Move>();
Move kw = new Move(100, 100, 10, 1);
vector.addElement(kw);
resize(500, 500);
}
public void start() {
if(!animating) {
animating = true;
thread = new Thread(this);
thread.start();
}
}
public void update(Graphics g) {
if(buffImage == null){
int w = getWidth();
int h = getHeight();
int type = BufferedImage.TYPE_INT_RGB;
buffImage = new BufferedImage(w, h, type);
Graphics2D g2 = buffImage.createGraphics();
g2.setPaint(getBackground());
g2.fillRect(0,0,w,h);
g2.dispose();
}
g.drawImage(buffImage, 0, 0, this);
}
public void run() {
while (animating) {
repaint();
try {
thread.sleep(10);
}
catch (Exception e){ }
Graphics2D g2 = buffImage.createGraphics();
g2.setPaint(getBackground());
g2.fillRect(0,0,buffImage.getWidth(), buffImage.getHeight());
for(int i = 0; i < vector.size(); i++) {
Move kw = vector.elementAt(i);
kw.advance();
BufferedImage image = images.get(i);
g2.drawImage(images.get(i), kw.x, kw.y, this);
}
g2.dispose();
}
}
private void loadImages() {
String[] ids = { "image2.png" };
for(int j = 0; j < ids.length; j++) {
try {
URL url = getClass().getResource(ids[j]);
images.add(ImageIO.read(url));
}
catch(IOException e) { }
}
}
}
class Move{
int x;
int y;
int d;
int vx;

Move(int X, int Y, int D, int VX) {
x = X;
y = Y;
d = D;
vx = VX;
}
public void advance() {
x += vx;
if(x >= 500)
vx=-Math.abs(vx);
if(x <= 0)
vx=Math.abs(vx);
}
}

Thanks









Related Tutorials/Questions & Answers:
Animation in Applets - Applet
Animation in Applets  Hello sir, I have a code for you .this code is for moving a plane in an applet,but unfortunatly this code is not working .can you kindly help me out to solve this problem. code: import
Applets?
Applets?  applets are using now a days   Please visit the following link: Applet Tutorials
Advertisements
APPLETS - Security
APPLETS  In java applets sun.misc is not working can any body help me for the alternate solution. while using new sun.misc.BASE64Encoder().encode(enc); i got runtime error... java.security.AccessControlException
Animation
animation
applets
Applets
Applets
Applets
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... the user's browser. Applets can be very useful, user friendly programs or can
ModuleNotFoundError: No module named 'animation'
ModuleNotFoundError: No module named 'animation'  Hi, My Python... 'animation' How to remove the ModuleNotFoundError: No module named 'animation' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'animation'
ModuleNotFoundError: No module named 'animation'  Hi, My Python... 'animation' How to remove the ModuleNotFoundError: No module named 'animation' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'animation'
ModuleNotFoundError: No module named 'animation'  Hi, My Python... 'animation' How to remove the ModuleNotFoundError: No module named 'animation' error? Thanks   Hi, In your python environment you
Free Java Applets
Free Java Applets       There are many free java applets available on the web that you can use in your website. These applets includes menu, clock, slide show, image animation
Version of jgoodies>animation dependency
List of Version of jgoodies>animation dependency
Version of com.jgoodies>animation dependency
List of Version of com.jgoodies>animation dependency
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... the user's browser. Applets can be very useful, user friendly programs or can
How to make an animation in the text, make an animation in the text, an animation in the text
How to make an animation in the text       This is about an animation example, in this example we are going to make animation in the text that is so easy
Bindows animation library
Bindows animation library       Bindows animation library enables adding animations to Bindows components - thus creating visual effects like pulsating buttons, fade-ins, fade-outs
ModuleNotFoundError: No module named 'mpl_animation'
ModuleNotFoundError: No module named 'mpl_animation'  Hi, My... 'mpl_animation' How to remove the ModuleNotFoundError: No module named 'mpl_animation' error? Thanks   Hi, In your python
animation in applet - Applet
animation in applet  Hello sir, your code is ok but what happend to this code can you modify this an tell me problem please code: import java.applet.*; import java.awt.*; import java.net.*; /* */ public class
Example code of jQuery animation
Example code of jQuery animation       Example code of jQuery animation The jQuery is very powerful framework. It provides a many animation effects that can
How to make a fade text animation, make a fade text animation, fade text animation
How to make a fade text animation       This is a fade text animation example, it will surely increase..._TO_REPLACE_3 ADS_TO_REPLACE_4 Animation: Click on the bottom of the tool bar
Maven Dependency animation >> 1.2.0
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> animation version1.2.0 in your project
Maven Dependency animation >> 1.4.2
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> animation version1.4.2 in your project
Maven Dependency animation >> 1.1.3
You should include the dependency code given in this page to add Maven Dependency of jgoodies >> animation version1.1.3 in your project
Maven Dependency animation >> 1.4.1
You should include the dependency code given in this page to add Maven Dependency of com.jgoodies >> animation version1.4.1 in your project
Careers in Animation
Careers in Animation You have all the praise for the characters like Mickey..., the people who can create magic with the visual effects. Animation is one... combination of text, images, graphics, animation and audio. Who can become
Servlet v/s Applets - Servlet Interview Questions
Servlet v/s Applets  what is difference between servlets & applets
ModuleNotFoundError: No module named 'lottie-animation-manager'
ModuleNotFoundError: No module named 'lottie-animation-manager'  Hi...: No module named 'lottie-animation-manager' How to remove the ModuleNotFoundError: No module named 'lottie-animation-manager' error? Thanks  
Animation in Java Applet
Applet is a java class that runs inside the internet browser. It uses Thread along with its methods for animation. Applet class implements the Runnable interface for animation program. Example of Animation in Java program
Programming using applets and oracle - Applet
Programming using applets and oracle  Develop an Online Examination software in java using applets as front end and oracle as back end. Software should handle at least ten users at a time. There are Multiple Choice questions
Applets in Java
Applet is a Java program embedded within HTML pages. Java applets is compatible with almost all the web browsers like Mozilla Firefox, Google Chrome, Internet explorer, Netscape navigator and others that are java enabled. Applets
Maven Repository/Dependency: jgoodies | animation
Maven Repository/Dependency of Group ID jgoodies and Artifact ID animation. Latest version of jgoodies:animation dependencies. # Version Release Date You can read more at: Maven
How to create Animation
How to create Animation       This section illustrates you how to create Animation. We.... The method fillRect() fills the rectangle with the colors showing animation
How to create Animation
How to create Animation       This section illustrates you how to create Animation. We.... The method fillRect() fills the rectangle with the colors showing animation
J2ME Frame Animation
J2ME Frame Animation       This application shows to set the Frame Animation and implement it in the canvas class. In this example we are creating a frame using Gauge class. When
Maven dependency for com.jgoodies - animation version 1.4.2 is released. Learn to use animation version 1.4.2 in Maven based Java projects
Maven dependency for  com.jgoodies  - Version 1.4.2 of animation released The developers of   com.jgoodies - animation project have... of  com.jgoodies - animation library is 1.4.2. Developer can use
Should we go for javascript or applets for online exam project using java
Should we go for javascript or applets for online exam project using java  Hi, I am new to java and i am working on online examination project.As soon as the candidate login successfully a window pop up should appear
J2ME Animation using repaint( ) method
J2ME Animation using repaint( ) method  ... are going to show you how to create an Image with animation. Here we have create... the CommandListner class. We have also used the predefined Canvas class to show the animation
java applets - Applet
Jav Applets - Applet
Applets - IDE Questions
java applets - Java Beginners
regarding applets - Java Beginners
Role of Java Applets in Web Application Development
In this article, we are discussing about the role of Java Applets in web application development. As we all know that an Applet is a simple Java program, which is written in Java programming language that extends the java.applet.
Problem with display of images in applets - Applet
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized  import java.awt.*; import java.awt.event.*; import java.applet.*; public class Textfields extends Applet implements
Line Animation in Java
Line Animation in Java       In this example we are creating an animated line. The color of  line is changing alternatively. We use drawLine() to draw a line
J2ME Timer Animation
J2ME Timer Animation       This application illustrates how to use the Timer class and implement it in the canvas class. In this Tutorial we have given you a good example

Ads