Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:04:30+00:00 2026-06-13T13:04:30+00:00

I have developed a little Swing application in which i have added a Square

  • 0

I have developed a little Swing application in which i have added a Square into my JFrame using a separate class component. Now i want to rotate this Square at its center, but I am only seeing a static Square which is not rotating at all.

This is my code…

public class Rotation extends JFrame {

    Rotation() {
        super("Animation of rotation about center");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400,400);

        add(new component());

        setVisible(true);
    }

    public static void main(String args[]){
        SwingUtilities.invokeLater(new Runnable(){public void run(){new Rotation();}});
    }
}

class component extends JPanel implements ActionListener {
    Timer timer;
    Rectangle.Double r=new Rectangle.Double(100,100,50,50);
    int theta=0;

    component() {
        timer=new Timer(10,this);
        timer.start();
    }

    public void actionPerformed(ActionEvent e) {
        if (theta==360){
            theta=0;
            theta++;
        }
        repaint();
    }

    public void paint(Graphics g){
        Graphics2D g2=(Graphics2D)g;
        g2.setColor(Color.GRAY);
        g2.rotate(theta);
        g2.fill(r);
    }
}

Could someone please help me identify and fix the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:04:31+00:00Added an answer on June 13, 2026 at 1:04 pm

    the problem was that i needed to make 2 changes:

    // 1.
    g2.rotate(theta,125,125);
    
    // 2.
    super.paint(g);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a little swing application in which i have drawn a square.Now
I have developed a website, using Twitter API. Now a little but important problem
I'm a little confused. We have developed an net 4.0 application. We use nhibernate
I have developed a website using Razor (Microsoft WebMatrix) and now I want to
I have developed a little game using XNA 4.0 and C# (new Project->Windows Game
Working with one of our partners, we have developed now two separate sets of
I have a very unreasonable requirement from my overlord. I developed a little application
I have an application developed using Adobe AIR. If the target machine is using
I have a little problem. I have developed a midlet application that call some
I have developed an application in mootools. But its going little slow coz of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.