Guest User

Untitled

a guest
Nov 21st, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. @Override
  2. protected void paintComponent(Graphics g)
  3. {
  4.     super.paintComponent(g);
  5.     Graphics2D g2d = (Graphics2D) g;
  6.     for(Ball ball : this.balls)
  7.     {
  8.         ball.draw(g2d);
  9.     }
  10.     g2d.dispose();
  11. }
  12.  
  13. @Override
  14. public void run()
  15. {
  16.     while(true)
  17.     {
  18.         try
  19.         {
  20.             Thread.sleep((long) (1000.0/60.0));
  21.         } catch (InterruptedException e)
  22.         {
  23.             e.printStackTrace();
  24.         }
  25.         repaint(); // This lags when moving mouse
  26.         // while the code below does not
  27.         // Graphics g = getGraphics();
  28.         // Graphics2D g2d = (Graphics2D) g;
  29.         // for(Ball ball : this.balls)
  30.         // {
  31.         //     ball.draw(g2d);
  32.         // }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment