A: 

Your code is incomplete and scrambled. Are you sure you don't have a loop terminating condition that can't occur? (i.e. an infinite loop). How many polygons are you drawing?

You could put in some logging to verify that the code does what you expect.

You could put in an early termination to the loop and use OS facilities to check memory usage to see if a leak (i.e. pack-ratting) is occurring.

RedGrittyBrick
sorry the thats not my code..it got scrambled.. it goes this way:
parin
for (int i=0;i<k;i++) { x= 100; y= 100; for(int j=0;j<k;j++) { if (cell[i][j]==0) break; if(i % 2 !=0) { p = new Polygon(); for (int h = 0; h < 6; i++) p.addPoint((int) (x + 50 * Math.cos(h * 2 * Math.PI / 6)),(int) (y + 50 * Math.sin(h * 2 * Math.PI / 6))); g.drawPolygon(p); } x+=75; } y+=45; }
parin
Comments don't format well, what I do is edit the question and post the code at the end after inserting a horizontal line and the word "EDIT" - then readers can work out what happened. In this case you could just correct the question and add a comment or a note at the end of the question like "Edit: scrambled code corrected".
RedGrittyBrick
What is the value of k?
RedGrittyBrick