Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to create an applet, with many squares inside?

807605Jul 21 2007 — edited Jul 24 2007
Hey,

I'm having problems creating an applet. Heres the image I need to recreate. The drawing should scale, so that it reaches the full width and
height of the applet.

http://img503.imageshack.us/my.php?image=graphicsafx5.jpg

I created a similar one (the code is below), but don't know how to modify it to create the image in the above link. Do I need a for loop? like for ( int i = 0; i < 10; ++i )
import java.applet.Applet;
import java.awt.*;

public class AprilTest1 extends Applet
{

   public void paint(Graphics g)
   {
	   Graphics2D g2 = (Graphics2D)g;

	   int width = getWidth();
	   int height = getHeight();

	   g2.setColor( Color.black );
	   g2.fillRect( 0, 0, width, height);

	   int pen_width = width/90 + 1;
	   g2.setStroke(new BasicStroke(pen_width));
	   g2.setColor( Color.white );


	   g2.drawRect( width/4, height/4, width/2, height/2);

   }

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2007
Added on Jul 21 2007
5 comments
173 views