// draw 500 balloons fixed size but random
colors and positions on the screen
applet with only a PAINT method
package untitled5;
import javax.swing.JOptionPane;
import javax.swing.JApplet; // import class JApplet
import java.awt.Graphics; // import class Graphics
import java.awt.*;
public class Applet1 extends JApplet
{
public void paint( Graphics g )
{
int n1,n2,n3,n4,n5;
int i=0;
do
{
// get random numbers for 3 RGB colors
// and random numbers for the Oval position
n1=1+(int) (Math.random()*254);
n2=1+(int) (Math.random()*254);
n3=1+(int) (Math.random()*254);
n4=1+(int) (Math.random()*200);
n5=1+(int) (Math.random()*200);
Color one = new Color(n1,n2,n3);
g.setColor(one);
g.fillOval(n4,n5,35,25);
i = i + 1;
}
while ( i
< 500);
}
}
|