java - How to repaint with timer? -


i want provide projectile motion timer. first of create timer , change location of x , y timer. when check x , y points updated can not repaint new x , y. how repaint panel , provide projectile motion? in advance. here code.

import java.awt.graphics; import java.awt.event.actionevent; import java.awt.event.actionlistener;  import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.timer;  public class deneme extends jpanel {      double positiony = 100;     double positionx = 100;     double velocityy = 20;     double velocityx = 20;     double acceleration = -10;     timer timer;      public deneme() {         timer = new timer(100, new mytimerlistener());     }      private class mytimerlistener implements actionlistener {         @override         public void actionperformed(actionevent e) {             update(0.09);             repaint();         }      }      void update(double dt) {         positionx += velocityx * dt;         positiony += velocityy * dt + acceleration * 0.5 * dt * dt;         velocityy += acceleration * dt;         system.out.println(positionx + " " + positiony);     }      @override     public void paint(graphics g) {         super.paint(g);         g.drawoval((int) positionx, (int) positiony, 15, 15);     }      public double positiony() {         return positiony;     }      public double velocityy() {         return velocityy;     }      public double positionx() {         return positionx;     }      public double velocityx() {         return velocityx;     }      public static void main(string[] args) {         new deneme().timer.start();         jframe frame = new jframe("basketball");         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setsize(1500, 1000);         frame.add(new deneme());         frame.setlocationrelativeto(null);         frame.setresizable(false);         frame.setvisible(true);     } } 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -