Manik
August 21st, 2000, 08:02 AM
Hi,
I m writing a java code, which draws a Grid(several boxes in a canvas). A separate class which extends the canvas does the job in the paint function. this class is then added to the JPanel. what happens is that if I want to draw a grid with 3 rows and 6 columns, it draws some extra boxes with some different sizes altogether. i m showing my code as follows:
import java.awt.Canvas;
import java.awt.*;
import java.awt.event.*;
public class PatternCanvas extends Canvas {
Grid[][] Gridarr = new Grid[15][10];
public PatternCanvas() {
}
public void paint(Graphics g){
int FactorX;
int FactorY;
int nFirst;
int nSec;
FactorY = -1;
for(nFirst = 0; nFirst <= 1; nFirst++){
int count = 0;
FactorX = 0;
FactorY++;
for(nSec = 0; nSec <= 2; nSec++){
Gridarr[nFirst][nSec] = new Grid();
Gridarr[nFirst][nSec].startX = FactorX * 20;
Gridarr[nFirst][nSec].startY = FactorY * 35;
Gridarr[nFirst][nSec].endX = (FactorX + 1)*20;
Gridarr[nFirst][nSec].endY = (FactorY + 1)*35;
g.drawRect(Gridarr[nFirst][nSec].startX,Gridarr[nFirst][nSec].startY,
Gridarr[nFirst][nSec].endX,Gridarr[nFirst][nSec].endY);
FactorX++;
System.out.println(Gridarr[nFirst][nSec].startX);
System.out.println(Gridarr[nFirst][nSec].startY);
System.out.println("Drawing rectangle "+ nFirst +" "+ ++count);
}
}
}
}
the output of the above code should be a grid with 2 rows and 3 cols... but instead it gives me an ouptut with 3 rows and 4 cols, the last two cols are of a different size altogether, so is the last row...
when i display the pixel positions for drawing the grids, it shows me correct points, but displays some unnecessary rectangles...
Please help... it is extremely urgent...
Thanks and regards,
I m writing a java code, which draws a Grid(several boxes in a canvas). A separate class which extends the canvas does the job in the paint function. this class is then added to the JPanel. what happens is that if I want to draw a grid with 3 rows and 6 columns, it draws some extra boxes with some different sizes altogether. i m showing my code as follows:
import java.awt.Canvas;
import java.awt.*;
import java.awt.event.*;
public class PatternCanvas extends Canvas {
Grid[][] Gridarr = new Grid[15][10];
public PatternCanvas() {
}
public void paint(Graphics g){
int FactorX;
int FactorY;
int nFirst;
int nSec;
FactorY = -1;
for(nFirst = 0; nFirst <= 1; nFirst++){
int count = 0;
FactorX = 0;
FactorY++;
for(nSec = 0; nSec <= 2; nSec++){
Gridarr[nFirst][nSec] = new Grid();
Gridarr[nFirst][nSec].startX = FactorX * 20;
Gridarr[nFirst][nSec].startY = FactorY * 35;
Gridarr[nFirst][nSec].endX = (FactorX + 1)*20;
Gridarr[nFirst][nSec].endY = (FactorY + 1)*35;
g.drawRect(Gridarr[nFirst][nSec].startX,Gridarr[nFirst][nSec].startY,
Gridarr[nFirst][nSec].endX,Gridarr[nFirst][nSec].endY);
FactorX++;
System.out.println(Gridarr[nFirst][nSec].startX);
System.out.println(Gridarr[nFirst][nSec].startY);
System.out.println("Drawing rectangle "+ nFirst +" "+ ++count);
}
}
}
}
the output of the above code should be a grid with 2 rows and 3 cols... but instead it gives me an ouptut with 3 rows and 4 cols, the last two cols are of a different size altogether, so is the last row...
when i display the pixel positions for drawing the grids, it shows me correct points, but displays some unnecessary rectangles...
Please help... it is extremely urgent...
Thanks and regards,