Running an animation using JCreator

1.2k Views Asked by At

I wrote this program which animates a red rectangle, using JCreator, I am finding difficulty in running the annimation, does anybody have any suggestions?

This is the program which animates the rectangle:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class Tutorial extends JPanel implements ActionListener
{
    Timer tm = new Timer(5, this);
    int x = 0 , velX = 2;
public void paintComponent(Graphics g){

    super.paintComponent(g);

    g.setColor(Color.RED);
    g.fillRect(x, 30, 50, 30);

    tm.start();
} 

public void actionPerformed(ActionEvent e){
    x = x + velX;
    repaint();
    }
 }
0

There are 0 best solutions below