eclipse - Java Applet, repaint 60times/sec method and polygons -


i have run method repaints 60times/sec , have paint method 4polygons in it. 4 buttons. when press 1st, poligons range in order red 1 on top, when press 2nd button polygons swop , green on top , others behind it. on eclipse , working, when run in terminal applet viewer, polygons not stoping , refreshing constantly. how make statement repaint 60time/sec polygon once when clicked on button.

public void run() {     long lasttime = system.nanotime();     double ns = 1000000000.0 / 1.0;     double delta = 0;     requestfocus();     while (running) {         long = system.nanotime();         delta += (now - lasttime) / ns;         lasttime = now;         while (delta >= 1) {             delta--;             update();             repaint();             validate();          }     } } 

and paint method

    public void paint(graphics g) {             // gives sharper graphics             g2 = (graphics2d) g;             g2.setrenderinghint(renderinghints.key_antialiasing,                     renderinghints.value_antialias_on);             windows.drawract(new color(0xa0, 0xd1, 0xe3), g2);     if (mlistener.firstwin) {                  add(analisysbtn);                 add(button_1);                 add(loadfilebutton);                 iffirst = true;                 iffirst2 = true;                 iffirst3 = true;                  test2 = 0;                 test3 = 0;                 test4 = 0;                 windows.drawcomparewindow(g2);                 windows.drawfourthwindow(g2);                 windows.drawthirdwindow(g2);                 windows.drawsecondwindow(g2);                 windows.drawfirstwindow(g2); }     } 

you adding components gui within paint(graphics g) method, should never do. method gets called repeatedly, many times outside of control, , needs blazing fast. no program logic, no gui structural change, , no long-running code should go in it.

as aside, you'll far better off using swing , overriding paintcomponent(graphics g) method of jpanel rather overriding paint directly in top-level window.

also should remember call super's method inside of override, first method call, allow component housekeeping drawing.

also, use swing timer , not while (true) loop run animation loop.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -