// same program as 6-1 except I showed you what it would
look
// like in applet form study the similarities with 6-1
// This applet also animation and uses a sleep method to
// pause the output so it can be seen. Students can judge from this
// and 6-1 to see how to take applications and convert to applets
// The "setXORMode" method is critical in animation. When
this
// mode is set drawing something twice cancells the appearance of
// the first drawing , making it disappear
// make you applet window larger 600 by 500 to see the entire
// animation
import java.awt.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
public class Applet1 extends JApplet
{
Thread th=new Thread();
public void paint(Graphics g)
{
int b;
g.setColor(Color.blue);
g.setXORMode(Color.white);
for(int a=1;a<800;a++) // start of loop
{
if (a<479) b=a;
else b=479;
g.fillOval(a,b,40,4);
try
{
th.sleep(25);
}
catch(Exception e)
{
}
if (a<479) g.fillOval(a,b,40,4);
else
{
b=479;
g.fillOval(a,b,40,4);
}
} // end of loop
}
} |