Note that there are some explanatory texts on larger screens.

plurals
  1. POGrid in Canvas, last cells' sizes are not the same as the others
    primarykey
    data
    text
    <p>How Do I paint the canvas with the grids having equal sizes? problem: <a href="http://tinypic.com/r/idvc0j/5" rel="nofollow">http://tinypic.com/r/idvc0j/5</a> the code draws the last cells with sizes not parallel to the other cells. what change do i have to do in the paint() method?</p> <pre><code>import java.awt.*; import javax.swing.*; public class Grid extends Canvas{ Cell[][] maze; int rows; int cols; Grid(int rows, int cols) { this.rows = rows; this.cols = cols; maze = new Cell[rows][cols]; } public static void main(String[] args){ JFrame f = new JFrame("Sample"); Grid x = new Grid(25,25); f.add(x); f.pack(); f.setVisible(true); f.setSize(600,600); f.setResizable(false); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paint(Graphics g) { int k; int width = getSize().width; int height = getSize().height; int htOfRow = height / (rows); for (k = 0; k &lt; rows; k++) g.drawLine(0, k * htOfRow , width, k * htOfRow ); int wdOfRow = width / (cols); for (k = 0; k &lt; cols; k++) g.drawLine(k*wdOfRow , 0, k*wdOfRow , height); } } class Cell { // private final static int NORTH = 0; // private final static int EAST = 1; // private final static int WEST = 2; // private final static int SOUTH = 3; // private final static int NO = 0; // private final static int START = 1; // private final static int END = 2; // boolean[] wall = new boolean[4]; // boolean[] border = new boolean[4]; // boolean[] backtrack = new boolean[4]; // boolean[] solution = new boolean[4]; // private boolean isVisited = false; // private boolean isCurrent = false; // private int Key = 0; // // public Cell(){ // for(int i=0;i&lt;4;i++){wall[i] = true;} // } // public void setStart(int i){Key = i;} // public int getKey(){return Key;} // public boolean checkVisit(){return isVisited;} // public void stepIn(){ // isCurrent = true; // isVisited = true; // } // public void stepOut(){isCurrent = false;} } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload