Hi, i have an existing applet animation program and i was playing around to see if i can get it to work using the JSwing classes. I extended the JPanel class and mangaged to get all the images i wanted to display. I then tried to make the JPanel class implement runnable. From their i was trying to use the Thread.stop() function to allow a pause in the execution of the JPanel. When i call the pause() function it does not display anything in the program. I am wondering how you would go about getting animation to work in the JPanel and which thread i would have to stop. I am also wondering how do you call repaint from the JPanel.<br>thanks tom<br>the following is my code<br><br>import java.awt.*;<br>import java.awt.event.*;<br>import javax.swing.*;<br><br>class MarinePanel extends JPanel implements Runnable<br>{<br><br>private Image marineback;<br>private Image marinestat;<br>private Image marinegroup;<br>private Image[] marineright = new Image[4];<br>private Image[] marineleft = new Image[4];<br><br>public MarinePanel()<br>{<br>Toolkit kit = Toolkit.getDefaultToolkit();<br>marineback = kit.getImage("marineback.gif"<br>marinestat = kit.getImage("marinestat.gif"<br>marinegroup = kit.getImage("marinegroup.gif"<br><br>marineright[0] = kit.getImage("marineright1.gif"<br>marineright[1] = kit.getImage("marineright2.gif"<br>marineright[2] = kit.getImage("marineright3.gif"<br>marineright[3] = kit.getImage("marineright4.gif"<br><br>marineleft[0] = kit.getImage("marineleft1.gif"<br>marineleft[1] = kit.getImage("marineleft2.gif"<br>marineleft[2] = kit.getImage("marineleft3.gif"<br>marineleft[3] = kit.getImage("marineleft4.gif"<br><br>MediaTracker tracker = new MediaTracker(this);<br><br>tracker.addImage(marineback,0);<br>tracker.addImage(marinestat,1);<br>tracker.addImage(marinegroup,2);<br>tracker.addImage(marineright[0],3);<br>tracker.addImage(marineright[1],4);<br>tracker.addImage(marineright[2],5);<br>tracker.addImage(marineright[3],6);<br>tracker.addImage(marineleft[0],7);<br>tracker.addImage(marineleft[1],8);<br>tracker.addImage(marineleft[2],9);<br>tracker.addImage(marineleft[3],10);<br><br>try { tracker.waitForAll(); }<br>catch (InterruptedException e) {System.out.println("Exception: " + e.getMessage()); }<br> <br>}<br><br>public void run()<br>{<br><br><br>}<br><br>void pause(int time)<br> {<br> try {<br> Thread.sleep(time);<br> } catch(InterruptedException e) {}<br> }<br><br>public void walkRight(int screenwidth, int screenheight, Graphics screen)<br>{<br><font color=red><b><i><u>this function is designed to have 4 images move accross the screen, and increment the x position as it moves</font></b></i></u><br><br>int arraycntr = 0,widthcntr = 0;<br><br>for(;widthcntr <= (screenwidth/2); widthcntr +=2)<br> {<br> if (arraycntr == marineright.length)<br> arraycntr = 0;<br><br> screen.drawImage(marineright[arraycntr],widthcntr,screenheight / 2,this);<br><font color=red><b><i><u>/*this is where the program needs to be stopped and the screen repainted, when i try the pause function it completely locks the computer <br>//pause(800);<br> //super.repaint();<br>*/</font></b></i></u> <br> arraycntr++;<br> }<br><br><br><br>}<br><br>public void walkLeft(int screenwidth, int screenheight, Graphics screen)<br>{<br>int arraycntr = 0,widthcntr = screenwidth/2;<br><br><br><br><br>}<br><br><br>public void paintComponent(Graphics screen)<br>{<br>super.paintComponent(screen);<br><br>//this sets the background each time this function is called it will tile any image<br>//this is specifically designed so that if the resolutino size changes so will the background<br>int screenwidth = 0, screenheight = 0, imagewidth = 0, imageheight = 0;<br><br>Toolkit tool = Toolkit.getDefaultToolkit();<br>Dimension dimen = tool.getScreenSize();<br>screenwidth = dimen.width;<br>screenheight = dimen.height;<br><br>while(imageheight <= screenheight)<br> {<br> while(imagewidth <= screenwidth)<br> {<br> screen.drawImage(marineback,imagewidth, imageheight, this);<br> imagewidth += marineback.getWidth(this);<br> }<br> imagewidth =0;<br> imageheight += marineback.getHeight(this);<br> }<br><br>screen.drawImage(marinestat, 0, 0,this);<br>screen.drawImage(marinegroup, screenwidth/2, screenheight/2,this);<br><br>walkRight(screenwidth,screenheight,screen);<br>}<br><br><br><br><br>}<br><br><br>class MarineFrame extends JFrame<br>{<br>public MarineFrame()<br>{<br>setTitle("Marines from StarCraft"<br><br>Toolkit tk = Toolkit.getDefaultToolkit();<br>Dimension d = tk.getScreenSize();<br>setSize(d.width,d.height);<br> <br>//this program sets up a normal window but the following code<br>//allows the program to close without forcing the os <br>//to close the prog<br>addWindowListener(new WindowAdapter()<br> { <br> public void windowClosing(WindowEvent e)<br> {<br> System.exit(0);<br> }<br> }<br>);<br><br><br>//this allows you to import a new image and it links it to the icon<br>//image<br>Image img = tk.getImage("marineleft1.gif"<br>setIconImage(img);<br><br>Container contentPane = getContentPane();<br>contentPane.add(new MarinePanel());<br>//contentPane.test = 60;<br>}<br><br>}<br><br>class jswingmarine<br>{<br><br><br><br><br>public static void main(String[] args)<br>{<br>JFrame frame = new MarineFrame();<br>frame.show();<br><br>}<br><br>}<br><br>/*<br>this is an attempt to make a simple animation program using various pictures and the swing<br>clases, started march<br>working on a loop to display an image tiled as the background image succes so far but it<br>only tiles one row ? 3/29/00<br><br>*/ <p>moses<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= </a><br>