I am trying to create an aplet wich will show rows of 5 boxes underneath eachother...I have been trying to do this with a nested loop but somehow the second set of five boxes doesn't start a new row...can someone please help me out with this? Here is the script: import java.awt.*; import java.applet.Applet; public class Tekenvelden extends Applet {

final int veldBreedte = 30; final int veldHoogte = 30; public void paint(Graphics g) {

tekenVeld(g, 10, 10, 15); } //--------------------------------------------------------------------------------------- private void tekenVeld(Graphics g, int x, int y, int aantal){

int box= 0; int row= 0; int rows= (aantal/ 5);

for (row = 0; row < rows; row++) {

for (box= 0; box < aantal; box++) { g.drawRect(x+(veldBreedte*box), y, veldBreedte, veldHoogte); g.drawString(" "+(box+1), x+(veldBreedte*box)+veldBreedte/2, y+veldHoogte/2);

aantal = 15 so in your inner for loop you are telling it to print 15 boxes per line. Change it to box < 5 and you'll get what you want. [ December 01, 2002: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt

Adam Polak
Greenhorn

Joined: Oct 28, 2002
Posts: 23

posted

0

It makes 3 rows of 5 boxes now, but I have another problem, the numbers in the boxes don't count through. Each row has numbers one 1-5, while row one should have 1-5, row two should have 6-10 and row three should have 10-15.