Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Applet Animation in Applets
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


seetaram
Animation in Applets
1 Answer(s)      4 years and 6 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){}

}
}
}

Advertisement
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
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
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
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
Servlet v/s Applets - Servlet Interview Questions
Servlet v/s Applets  what is difference between servlets & applets
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
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
Advertisements
 

 

 

DMCA.com