Friday 8 March 2013


 PROGRAM- 1

   BOUNCING BALL

import java.awt.*;
import java.awt.image.*;
import java.applet.*;
/*<applet code="ball.class" width=810 height=600></applet>*/
public class ball extends Applet implements Runnable
{
int x,y,d=20,height;
private Image img;
private Graphics g2;
public boolean fall;
int r,h;
double delay=4;
public void init()
{
x=0;
y=0;
r=d/2;
height=500;
fall=true;
}
public void start()
{
Thread thread=new Thread(this);
thread.start();
}
public void run()
{
while(true)
{
if(fall && y<530){
y++;
if(y%3==0)x++;
delay-=.003;
}
else if(!fall && y>h)
{
y--;
if(y%3==0)x++;
delay+=0.003;
}
if(y>=525)
{fall=false;height=height*2/3;}
if(y<=h)
{fall=true;y=h;}
repaint();
try{
Thread.sleep((int)delay);
} catch(InterruptedException e) {
e.printStackTrace();
}
}
}
public void update(Graphics g)
{
if(img==null){
img=createImage(this.getSize().width,this.getSize().height);
g2=img.getGraphics();
}
g2.clearRect(0,0,this.getSize().width,this.getSize().height);
paint(g2);
g.drawImage(img,0,0,this);
}
public void paint(Graphics g)
{
g.drawLine(0,550,810,550);
g.fillOval(x,y,d,d);
h=530-height;
}
}



 A BLOG FOR JAVA-APPLET PROGRAMS

     ABOUT JAVA APPLET : 

A Java applet is an applet delivered to users in the form of Java byte code. Java applets can be part of a web page and executed by the Java Virtual Machine (JVM) in a process separate from the web browser, or run in Sun's AppletViewer, a stand-alone tool for testing applets. Java applets were introduced in the first version of the Java language in 1995, and are written in programming languages that compile to Java byte code, usually in Java, but also in other languages such as Jython, JRuby, or Eiffel 
Java applets run at very fast speeds comparable to, but generally slower than, other compiled languages such as C++, but until approximately 2011 many times faster than JavaScript. In addition they can use 3D hardware acceleration that is available from Java. This makes applets well suited for non-trivial, computation intensive visualizations. As browsers have gained support for hardware accelerated graphics thanks to the canvas technology (or specifically WebGL in the case of 3D graphics), as well as just in time compiled JavaScript, the speed difference has become less noticeable.
Since Java's bytecode is cross-platform or platform independent, Java applets can be executed by browsers for many platforms, including Microsoft Windows, Unix, OS X and Linux. It is also trivial to run a Java applet as an application software with very little extra code so that it can be run directly from the integrated development environment (IDE).