So I'm attempting to rotate an image using animation by having it change images to a new one that has been rotated 22.5 degrees. I'm doing this by having 1 class inheriting from a JFrame and the other class from a JPanel However it is not doing anything. Here is the code..
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.event.*;
public class LogoAnimatorJPanel extends JPanel implements ActionListener
{
protected ImageIcon[] images = new ImageIcon[16] ;
private int currentImage = 0;
private Timer animationTimer;
public LogoAnimatorJPanel()
{
for ( int count = 0; count < images.length; count++ ){
images [count] = new ImageIcon("car/yellowCar" + count + ".jpg");
}
startAnimation();
}
public void paintComponent( Graphics g )
{
super.paintComponent( g );
images[ currentImage ].paintIcon( this, g, 50 , 50 );
currentImage = ( currentImage + 1 ) % images.length;
}
public void startAnimation()
{
animationTimer = new Timer(20, this);
animationTimer.start();
}
public void actionPerformed( ActionEvent actionEvent )
{
repaint();
}
}
displayAnimator
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class displayAnimator extends JFrame
{
private LogoAnimatorJPanel fp;
public displayAnimator()
{
setTitle("car");
setBounds(200,200,200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = getContentPane();
cp.setLayout(null);
fp = new LogoAnimatorJPanel();
fp.setBounds(180, 25, 100, 100);
cp.add(fp);
}
public static void main(String[] args)
{
displayAnimator testRun = new displayAnimator();
testRun.setVisible(true);
}
}
Any Ideas?