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 6682883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:45:26+00:00 2026-05-26T04:45:26+00:00

I want an circular movement of an image in JAVA, i thought I have

  • 0

I want an circular movement of an image in JAVA, i thought I have the solution but it doesn’t work and i’m a bit clueless now.

For calculating the points it needs to go im using pythagoras to calculate the height (point B).

if it does one round im satisfied but more rounds would be cool.

The image size is around 500 x 300 pixels.

Here’s my code :

package vogel;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

public class Vogel extends Component {
    private int x;
    private int r;
    private int b;
    BufferedImage img;

    public vogel() {
       try {
           img = ImageIO.read(new File("F:/JAVA/workspace/School/src/vogel/vogel.png"));
       } catch (IOException e) {
       } 
       r = 60;
       x = 10;
    }

    @Override
    public void paint(Graphics g) {
        for(int i = -x; i <= x; i++) {      
            b = (int)Math.sqrt(r^2 - i^2);
            g.drawImage(img, x, b, this);
        }        
    }

    public static void main(String[] args) { 
    JFrame f = new JFrame("Vogel");   
    f.setSize(1000,1000);
    f.add(new Vogel());        
    f.setVisible(true);

    for (int number = 1; number <= 1500000; number++) {
        f.repaint();

        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {}
        }
    }
}
  • 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-05-26T04:45:27+00:00Added an answer on May 26, 2026 at 4:45 am

    Using your loop in the paint(Graphics) method, it draws 21 birds with one repaint.

    You should do it with an angle stored in an object variable and use the Math.sin() and Math.cos() function calculate the x and y position. The angle should be increased with every repaint().

    To add:

    // To control the radius of moving
    private final double MAX_X = 200;
    private final double MAX_Y = 200;
    
    private double angle = 0;
    
    @Override
    public void paint(Graphics g) {
        // increase angle (should be a double value)
        angle += 0.1;
    
        // rotate around P(0/0), assuming that 0° is vector (1/0)
        int x = (int) (Math.cos(angle) * MAX_X);
        int y = (int) (Math.sin(angle) * MAX_Y);
    
        // move P to center of JFrame (width and height = 1000)
        x += 500;
        y += 500;
    
        // image is 500x300, calc upper left corner
        x -= 250;
        y -= 150;
    
        // draw
        g.drawImage(img, x, y, null);
    }
    

    To remove:

    private double x, b, r;
    

    So this is the code, try it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ImageButton: I want to make the image (circular play image) bigger.
I have one image in circular format and i want to rotate in circular
I have created sample circular UIScrollview.it works fine.but i want to scroll through NSTimer
I want to place a small circular login image on the border of div
What I want to do I have a circular custom NSView subclass, and I
I have a horizontal scrollView which contains 2 images.The scrollView is circular.What I want
I want to draw a string say stackoverflow in circular view like below image
I have this div which acts a lens in zooming of the image. But
I want to make a video MediaElement into a circular shape, but i cannot
I have a circular queue of ordered items. I want to know if an

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.