Home Answers Viewqa Applet Animation in Applets

 
 


seetaram
Animation in Applets
1 Answer(s)      3 years and 2 months ago
Posted in : Applet

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 Pages:
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 which do animation have a start() method. If your applet doesn't... Java NotesApplets Why no applets in these notes These notes were originally written using applets almost entirely. However, all applet examples are being
Applets?
Applets?  applets are using now a days   Please visit the following link: Applet Tutorials
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
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
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
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
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
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... this work five time as I have given below. Animation: Click on the bottom
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
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
Servlet v/s Applets - Servlet Interview Questions
Servlet v/s Applets  what is difference between servlets & applets
How to create Animation
How to create Animation       This section illustrates you how to create Animation. We... 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... fillRect() fills the rectangle with the colors showing animation. Here
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
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
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
Bouncing Ball
Java: Example - Bouncing Ball This program does a simple animation. Animation is done by creating a timer which calls an ActionListener at fixed... 22 23 24 25 26 27 // File: animation/bb/BBDemo.java // Description
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
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
The animation of image using the 'animate' effect of jQuery
The animation of image using the 'animate' effect of jQuery... function of jQuery. We can do following things during animation using it's...;, height: 'toggle' }, 5000, function() { // Animation complete
Animated Web Design
Animated Web Design Animation needs the higher skill of work and experience, and animation on web not only need the art but also need the technical skills... animation must have following merits: Original concept and higher imagination
Java & JEE books Page2
; Applets This lesson talks about the basics of applets, advantages of applets over applications, how to load applets in a web page, how to convert applications to applets and how applets work. You should thoroughly understand
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
Photoshop Tutorial : How to make a animated text.
;  This is an animated example, I have made here a text animation... this. For animation: Now we have to use Image Ready to make animation so click... Ready. In the Image Ready, we have to adjust the layers for correct animation
Applet versus Application
;    Applets as previously described, are the small programs while applications are larger programs. Applets don't have the main method while in an application execution starts with the main method. Applets can run in our
Free Java stuffs
for cell phones Free Java Applets
Top-level Listeners
; A common way to write simple applets is to use the use the applet itself
Java JAR Files
Java JAR Files       A JAR file is a collection of  class files and auxiliary resources associated with applets and applications. The Java Archive (JAR) file format enables
&lt;APPLET&gt; Tag Parameters: The &lt;PARAM&gt; Tag
directly to a Java applet. Parameters are to applets what command-line... to applets are: First, add the PARAM tag (with values) to the HTML source file... These parameter values are retrieved by Java applets using the getParameter() method
Java Update
Update 2 provides improved behavior for applets in Safari and increased stability.... The Kernel online installer lets first time Java users run applets... Java applets and applications and any additional libraries that may
Basic Filter
of animation at the time selector is run etc. Some of the key filters... select the element which are in advancement of an animation at the time selector... which are in progress of animation. toggleClass("colored") change
The Java Applet Viewer
; Applet viewer is a command line program to run Java applets... that inherits the Applet. We generally use web browsers to run applets. Its not always... that acts as a test bed for Java applets. The working of Applet viewer is a bit

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.