How to create java gui animation? - java

I have a line drawn in my gui and I want to put the arrow moving on the line. It is abit of animation and I can't seem to find it on the google. I hope you guys can help me out with Java gui animation.

Use a Thread with a loop inside its run() method. On each step of the loop change the position of the arrow a little bit, repaint the user interface (or only the part that you know has changed) and wait for about 30ms or so.

The subject of UI animation is far beyond the scope of a single answer, you could literally write a book about it. Fortunately somebody has - Filthy Rich Clients.

Related

Timer in Greenfoot

I'm making a game right now and want to add a timer to count down to my end game screen, I can get the text to show up on my game screen but the numbers won't go down.
Any feedback would help!
Biased note: Greenfoot is a great tool to learn to program in Java. Keep going! But learn to read documentation[1], please.
You are calling subtractTime() only in the constructor Timer(). This way it will be called only once at creation time of your Timer object.
Call it in the act() method instead.
It will be called every time when the Greenfoot system lets all actors and the current world, well, act. The time between the calls is controlled by the "Speed" control below the world's frame, or by the specific methods of the class Greenfoot.
If you need "real-time" values like seconds, do some research how to obtain seconds or milliseconds.
[1]: You can read Greenfoot's documentation in the Editor window by double-clicking on "World" or "Actor" in the class diagram on the right.

Java: KeyListener being interrupted

Good Day (or night) Everyone!
I was lately developing a little game and decided to use javax.swing (basically JFrame stuff xD) and KeyListener.
Now, my basic game loop was a thread, so it went smoothly with my KeyListener.
So now I was able to get input from the KeyListener, process the input, and make an output.
But then I had to make a function that would draw all the things that I wanted drawn on the JFrame.
This took quite a bit of the computing power I had and made my game slower. But that wasn't the problem.
The problem occurred when I had to use that function multiple times almost at once, which didn't let the KeyListener run at all.
So now my big question is, what would be the preferred method to prevent the interruption?
Can I use some sort of Thread but for voids to prevent this?
Big Thanks from Me to Whoever solves my question! :D

Simulating a Mouse Event on A Minimized Window Java

So I want to be able to simulate mouse clicks on my window/frame, but in the background. This means I cant use the Robot class because it takes control of the OSes mouse which is not what I want (please guys, I know of and use the Robot class, it's not what I need).
I want the program to think I clicked on part of it (x,y on the frame) even when minimized (doesnt have to minimized but at least out of focus). I dont want it to take over my computer since it should ideally be a background task.
I did a little bit of research before posting and I read that I could make an Applet and then use the "reflection class"(?) and mouselisteners to invoke mouse events on the frame itself rather than through the OS. Not sure if itll work cause the explanation was pretty meh and the guy said they could communicate individually if he had problems :/.
Kind of wondering if it's possible at this point. If it cant be done in java, I know a little python, so if there's a solution for it in python, that could work to.
TLDR: Need to simulate mouseclicks on my frame, but it cant use the os mouse and should ideally work when the application is out of focus/in the background.
Thanks in advance :D

How to create a "Pick Whip" (Adobe After Effects) in Swing

In Adobe After Effects there is something called a "pick whip". It allows you to click on a dot on one object and drag a line from that dot to another element, making a connection between the two. I would like to duplicate this feature in my Java program using swing. I honestly have no idea where to start.
If I've done a bad job explaining what I mean, please comment so I can improve it. If there is some way outside of Swing to do this, I'm willing to try it.
Here are some examples of what I am trying to achieve:
LinePanel illustrates how to animate the line as it is rendered, but you'll have to paint on the glass pane or among JLayeredPane instances to see the line above existing components.

Java: How to do GUI animations?

In all my time so far working with Java and its Swing GUI framework, I've never quite figured out (or even attempted to try) how to make the interface animate components.
Say I wanted the screen to slide left into the next screen or have a JLabel "fly" to a new location. Perhaps you want a menu to smoothly open in an animated fashion. How does this work?
Do you have to use SwingWorker? Even if that's the case... how can you control the painting of components if the layout manager is already doing that?
Have a look at the book Filthy Rich Clients, you will find some really good answers there.
I think that there no reason for use SwingWorker, SwingWorker is designated for running long Backgroung Task(s) on output would be on Event dispatch Thread,
For animations in Swing is there javax.swing.Timer, examples here
Take a look at Trident library. You can use it to interpolate various properties in your class.

Categories