I am.working. on a Netbeans Java project in JFrame
form (a GUI application) where I want to move a JLabel
into circular path. Can any tell or help to how to do that?
Asked
Active
Viewed 492 times
-2

Andrew Thompson
- 168,117
- 40
- 217
- 433

Deepanshu Singh
- 59
- 1
- 1
- 5
-
1Your question is very broad, and as such, it's hard to know how to answer it specifically. Can you please tell us: 1) what have you tried? 2) Where are you stuck? – Hovercraft Full Of Eels Aug 25 '13 at 02:31
-
I want to move jlabel in circular path I m using x axis and y axis . so that when I click.on button. it got move in a circle – Deepanshu Singh Aug 25 '13 at 02:33
-
For better help sooner, post an [SSCCE](http://sscce.org/) (rather than word descriptions). – Andrew Thompson Aug 25 '13 at 02:37
-
You're posting a "want" not a question. *Again*, please show us what you've tried and please explain how it doesn't work. – Hovercraft Full Of Eels Aug 25 '13 at 02:38
-
1I dont know what to do so how I can show you what I have done? – Deepanshu Singh Aug 25 '13 at 02:40
-
See also this [`AnimationTest`](http://stackoverflow.com/a/3256941/230513). – trashgod Aug 25 '13 at 02:42
-
*"how I can show you what I have done?"* Well, you say.. *"I am.working. on a Netbeans Java project in JFrame.." ..so do you have any code that shows a frame? Does it add a label to the frame? Show that! There are many reasons to make an SSCCE. One reason is that people who are interested in answering can play with the code without needing to do the basics of making the frame. If OTOH you have absolutely no code, then it brings us back to the reason I voted to close this. "Must show a minimal understanding of the problem" Stack Overflow is not a help desk or a place to recruit a tutor. – Andrew Thompson Aug 25 '13 at 03:10
-
[Example](http://stackoverflow.com/questions/12964983/rotate-image-around-character-java/12971987#12971987) of calculating the x/y poisition of circle based on a give angel. – MadProgrammer Aug 25 '13 at 08:56
1 Answers
4
It sounds like you haven't done anything yet, and when that happens and you need to get started, then you should try to break the main problem into little steps, and then try to solve each little step one at a time, including looking at references for each of these steps such as using a Timer, doing animation, positioning components, etc...
So general recommendations:
- Look up using a Swing Timer (or just click on link)
- Use the Timer to drive your animation.
- You can move a JLabel if the layout is null, but this is generally to be avoided.
- Consider instead using a custom layout if you absolutely need to move a JComponent (the JLabel) along a prescribed path.
- Or if you just want to move an image, then draw the image inside of a JPanel's
paintComponent(...)
method, setting its position with two int fields that are changed by the Timer. This JPanel of course will need to be displayed in your GUI. There are lots of examples on how to do this on this site, some written by me (for example), that simple searching can help you find. - But most important, take the first steps, do something, anything, that moves you forward with this project.
Then when you try this if it doesn't work, show your code and we'll be much better able to help.

Community
- 1
- 1

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373