Java -> Can't close window while paint -
i can't close window while painting (i have loop painting 1000x times every 1/10 seconds).
code of program:
public class mycanvas extends canvas{ private static final long serialversionuid = 1l; private int x = 0; private int y = 0; private int = 0; private int innerw; private int innerh; jframe f; mycanvas() { super(); f = new jframe(); f.setsize(500,500); f.setbackground(color.blue); f.setdefaultcloseoperation(jframe.exit_on_close);; f.setlayout(new gridlayout());; f.add(this); f.setvisible(true); for(i = 0; i<1000; i++) { innerw = f.getwidth() - f.getinsets().left - f.getinsets().right; innerh = f.getheight() - f.getinsets().top - f.getinsets().bottom; x = (int) (math.random() * innerw); y = (int) (math.random() * innerh); try { timeunit.milliseconds.sleep(100); } catch (interruptedexception e) { e.printstacktrace(); } repaint(); } } public void paint(graphics g) { graphics2d g2d = (graphics2d) g; super.paint(g); do{ g2d.setcolor(new color((int) (math.random() * 16777216 ))); g2d.filloval(x, y, 25, 25); f.setdefaultcloseoperation(jframe.exit_on_close); } while(i<1000); } }
Comments
Post a Comment