Skip to main content

Display alternate image in java applet



// here we have used s1 and s2 images
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.applet.*;

import java.applet.Applet;

/*<applet code="s" height=678 width=678></applet>
  */
public class s extends Applet implements Runnable
{
int x=1;
String un="";
Thread t;
public void init()
{
t=new Thread(this);
t.start();
}
public void run()
{
try
{
while(true)
{
repaint();
t.sleep(500);

}
}catch(Exception e)
{
System.out.println(e);
}
}

public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{

Dimension d=getSize();
g.fillRect(0,0,d.width,d.height);
  try {
un="s"+x+".jpg";
        g.drawImage(ImageIO.read(new File(un)), 0, 0, null);
x+=1;
if(x==3)
x=1;
       }
catch (IOException e)
{
}
}
}

Comments

Popular posts from this blog

unix commands