CrazyEngineers
  • rotating a rectangle animation problem

    TaraJava

    Member

    Updated: Oct 26, 2024
    Views: 1.1K
    package rotatinganimation;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.*;
    import java.awt.Graphics2D;
    import java.awt.geom.*;
     
    public class Demo
    {
    Thread t1;
    int degree=8;
    public Demo()
    {
    JFrame frame=new JFrame("Tara Animation");
    frame.setSize(500,500);
    frame.add(new Rotate(),BorderLayout.CENTER);
    frame.setVisible(true);
    }
     
    class Rotate extends JPanel implements Runnable
    {
    public void start()
    {
    if(t1==null)
    {
    t1=new Thread(this);
    t1.start();
    }
    }
    public void run()
    {
    for(int i=0;i<16;i++)
    {
    repaint();
    try{
    Thread.sleep(10);
    }
    catch(Exception ex){}
    }
    }
    public void paint(Graphics g)
    {
    Graphics2D graph2=(Graphics2D)g;
    graph2.setColor(Color.red);
    graph2.translate(200,200);
    graph2.rotate(Math.PI/Math.toRadians(degree));
    Rectangle2D.Double rect=new Rectangle2D.Double(50,80,50,50);
    graph2.fill(rect);
    }
    }
     
    public static void main(String[] args)
    {
    Demo d=new Demo();
     
    }
    }
    
    *****am expecting these code to provide animated rotating rectangle but its not working somebody can you please check it ************
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register