0

I am trying to move a image across a jpanel but a for loop is not working. what method allows you to move a image icon. It shows up but doesn't move when i tried everything.

public class Picture extends JPanel implements Runnable
    {
        public Picture()
        { 
        }//constructor

         public void paintComponent(Graphics g)
         {
             super.paintComponent(g);
             //aPic.paintIcon(this,g,xloc,yloc);
             g.draw(aPic,100,20,this);
         }//paint

         public void run()
         {
             this.repaint();
         }//run
        }
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
kyrren love
  • 31
  • 1
  • 1
  • Animation in Swing is a common enough subject with a number of well documented solutions. The first thing you need to do is understand how painting works in Swing, [Performing Custom Painting](https://docs.oracle.com/javase/tutorial/uiswing/painting/index.html) and [Painting in AWT and Swing](http://www.oracle.com/technetwork/java/painting-140037.html) is a good place to start. It will help you understand the common pitfalls and why some solutions are recommended over others – MadProgrammer Feb 24 '18 at 22:00
  • The next step is to understand how concurrency works in Swing. [Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html) and [How to Use Swing Timers](https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html) are a good place to start. This is important as you need to know how to perform a series of operations over a period of time while not blocking the API and prevent it from been updated – MadProgrammer Feb 24 '18 at 22:01
  • Animation is a complex subject, but the basics of which can be applied across a number of different frameworks (but the theory remains the same) - Animation is tricking the observer into thinking something is moving. Simply, this is updating the state of the object you are animating often enough and with the right amount of change to fool the observer into thinking the object is moving – MadProgrammer Feb 24 '18 at 22:03

0 Answers0