Login    New User    Forgot Password    Help      

Box Applet

Java Tutorials

// color box
import java.awt.Graphics;
import java.awt.Color;

public class app5 extends java.applet.Applet
{
public void paint(Graphics g)
{

int rval, gval, bval;
for (int j = 30; j < 300; j += 30)
{
for (int i = 5; i < 300; i += 30)
{
rval = (int)Math.floor(Math.random() * 256);
gval = (int)Math.floor(Math.random() * 256);
bval = (int)Math.floor(Math.random() * 256);
g.setColor(new Color(rval,gval,bval));
g.fillRect(i-1, j-1, 25, 25);
g.setColor(Color.black);
g.drawRect(i-1, j-1, 25, 25);
}
}
}
}

Output

Output in applet

Java Tutorials