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

  • Home
  • SEARCH
  • 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 7813987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:03:17+00:00 2026-06-02T05:03:17+00:00

Hi I am having an issue solving a problem that I need to resolve

  • 0

Hi I am having an issue solving a problem that I need to resolve to continue with a project I am doing. I want to animate a line from a corner of a JPanel to an arbitrary point on the border of the panel determined by the user inputted angle.

Alot of posts similar to this recommend the swing timer with incrementing the x2, y2 of a line but my problem is that I don’t know the line that is going to be drawn because it is determined by the function I will have to write that takes into account the angle (slope).

Say it happens to be 30 degrees…I wouldn’t be able to just increment x2 and y2 because i don’t know what the rise and run is in pixels to animate the correct angled line….

Are there any functions available to help with this maybe in Math or anything….I am also looking into javafx.animation

I’m not looking for a solution necessarily just to be pointed in the right direction I guess
thanks

Edit
From another post:
Hi I am trying to do a project which essentially shows the path of a pool ball traversing a pool table. I understand the underlying trigonometry but I have no experience with animation in Java.

Right now I have a JPanel that is functioning as the pool table. The ball will always start from a certain point.

I know how to “draw” the line using paint() but how can I animate it easily.

My hunch is to animate the ball’s path (basically animate a growing line) by using a loop with a swing timer causing a delay with each pass and drawing the next pixel of the line with each pass of the loop. My problem is how can I reference these pixel values. For example if the line was horizontal or vertical you could just increment the y2 or x2 value and redraw the line with each pass but if the slope of the line is able to change I understand how to get the endpoint of the line but what about each active pixel coordinate on the line. Can I “draw” a line object and somehow reference each pixel in it’s path with some type of method. I’ve looked a little bit into PathIterator() but I’m not convinced I’m on the right track (or I’m more concerned that I’m not on the easiest, more high level track).

Is there an easier way to do this or am I at least on the right track? I am researching on my own but I’m getting worried because it’s for a software engineering project in school and the animation aspect is really holding our group back.

  • 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-02T05:03:18+00:00Added an answer on June 2, 2026 at 5:03 am

    My hunch is to animate the ball’s path (basically animate a growing line) by using a loop with a swing timer causing a delay with each pass and drawing the next pixel of the line with each pass of the loop.

    Yes, that’s about right.

    My problem is how can I reference these pixel values.

    I wouldn’t worry about pixel values. Instead separate your problem into its constituent parts —

    • Give your class an int constant to represent the time slice length. You may wish to experiment with this.
    • Have code for the physics of the ball, that will understand the ball’s location for each slice of time
    • Have separate code that draws the ball at it’s current location.
    • The timer will update time, and call your physics code to update the location of the ball. The physics part will set class fields that describe this location (ballX and ballY variables perhaps), and then will call repaint() so that the JPanel’s paintComponent(...) method can use the ballX and ballY variables to draw the ball at the correct location.
    • Using separate classes for the logic vs the view portion of the program would be best, but perhaps not necessary at an early stage.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of an issue solving a jQuery form problem. Basically I
I having issue that content assistant / intellisense is working in methods such as
Having an issue here that I have tried everything I can think of but
I'm new to mocking, and I'm having a hard time solving an issue with
I am having issue when sending data from Service to Activity through Notification ,
I'm having issue with Action Listener of a JTable that being updated according the
Having problems solving a basic (but new to me) custom taxonomy issue--I have used
I am having issue with Google line chart API. When I reload the div,
I am having issue with opencv's Sobel edge detector. From its documentation it seems
I'm porting one of my projects from C# and am having trouble solving a

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.