public void drawDistances ( Graphics g1 ) { Graphics2D g = ( Graphics2D ) g1 ; int c = matrix . getRowDimension ( ) ; int d = matrix . getColumnDimension ( ) ; float scale = getScale ( ) ; int width = Math . round ( scale ) ; for ( int i = 0 ; i < c ; i ++ ) { int ipaint = Math . round ( i * scale ) ; for ( int j = 0 ; j < d ; j ++ ) { double val = matrix . get ( i , j ) ; int jpaint = Math . round ( j * scale ) ; Color color = cellColor . getColor ( val ) ; g . setColor ( color ) ; g . fillRect ( ipaint , jpaint , width , width ) ; } } }
For each element in matrix draw it as a colored square or pixel .