//Applet code to move object form left to right.
import java.awt.*;
import java.applet.*;
import java.lang.Thread;
import java.lang.*;
public class Applet1 extends Applet
{
Thread t;
int i;
int x=14,y=14;
public void init()
{
t=new Thread();
}
public void paint(Graphics g)
{
for(x=14;x<=getWidth();x=x+5)
{
g.setColor(Color.BLACK);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(Color.RED);
g.fillOval(x,y,40,40);
repaint();
try
{
t.sleep(50);
}
catch(Exception e)
{}
}
}
}
execution step:--
c:\javac Applet1.java
c:\appletviewer Applet1
import java.awt.*;
import java.applet.*;
import java.lang.Thread;
import java.lang.*;
public class Applet1 extends Applet
{
Thread t;
int i;
int x=14,y=14;
public void init()
{
t=new Thread();
}
public void paint(Graphics g)
{
for(x=14;x<=getWidth();x=x+5)
{
g.setColor(Color.BLACK);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(Color.RED);
g.fillOval(x,y,40,40);
repaint();
try
{
t.sleep(50);
}
catch(Exception e)
{}
}
}
}
execution step:--
c:\javac Applet1.java
c:\appletviewer Applet1
0 comments :