Create a Java applet that fills the applets drawing area wit
Create a Java applet that fills the applet\'s drawing area with square boxes and randomly chosen colors.
In simple Java please
Solution
import java.awt.Graphics;
import java.awt.Color;
public class ColorBoxes extends java.applet.Applet
{
public void paint(Graphics g)
{
int rval, gval, bval;
for (int j = 30; j < (size().height -25); j += 30)
{
for (int i = 5; i < (size().width -25); 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, j, 25, 25);
g.setColor(Color.black);
g.drawRect(i-1, j-1, 25, 25);
}
}
}
}
