PDA

View Full Version : I need help.


silver90
11-10-03, 08:55 PM
I am trying to do an applet that will print a big Rectangle if the summ of i and j is odd and a small one if the summ is even.
This is my code. Do you have any idea why it is printing only big or small rectangle?

Thank you

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Sah extends Applet
{


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

int i=0;
int j=0;
int width = 320;

for(j =0; j< (width - 1); j += 40)
{

for(i =0; i< (width - 1); i += 40)
{
if ((i+j)%2 ==0)
{
Rectangle myBig = new Rectangle( i, j, 40, 40);
g2.draw(myBig);

}
else
{

Rectangle mySmall = new Rectangle( i, j, 4, 4);
g2.draw(mySmall);
}

}


}




}

}

esh
11-11-03, 12:18 PM
not really following what exactly you are trying to do here...


you aren't taking any user input, all your values are hard coded, so the shapes will never change.



import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class Sah extends Applet
{
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
int i=0;
int j=0;
int width = 320;

for(j =0; j< (width - 1); j += 40)
{
for(i =0; i< (width - 1); i += 40)
{
if ((i+j)%2 ==0)
{
Rectangle myBig = new Rectangle( i, j, 40, 40);
g2.draw(myBig);
}
else
{
Rectangle mySmall = new Rectangle( i, j, 4, 4);
g2.draw(mySmall);
}
}
}
}
}