Forums Register Login

move from a position to a new position with animation

+Pie Number of slices to send: Send
Hey guys,
I started a few days ago to program with swing and I got now an insoluble problem.
I want to move the red graphic from a position a to any other position b.
it should move and not telepot.
It would be great if you could help me.

+Pie Number of slices to send: Send
1. Learn to indent and otherwise format code for readability: http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

2. The Swing method to override for custom painting is paintComponent(...) not paint(...): http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html

3. All Swing constructors and methods should be invoked on the EDT, not on the Main Thread: http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html

4. The JFrame method show() inherited from Window is deprecated. See the API for the method you should be using instead.

6. Calling repaint() from within the constructor of a GUI component class is meaningless as the component is yet to be rendered.

For animation, use a javax.swing.Timer: http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html

Why does your application have two JFrames?

edit
7. Painting method overrides are strictly for painting. Not for constructing components, not for showing another window, not for loading resources, not for application logic. Remember that you have absolutely no control over how often or how many times a painting method is executed.
+Pie Number of slices to send: Send
> 7. Painting method overrides are strictly for painting. Not for constructing components, not for showing another window, not for loading resources, not for application logic.

looks like it needs to be posted in braille:

https://coderanch.com/t/599910/GUI/java/include-jpg-Graphic
+Pie Number of slices to send: Send
 

Michael Dunn wrote:> 7. Painting method overrides are strictly for painting. Not for constructing components, not for showing another window, not for loading resources, not for application logic.

looks like it needs to be posted in braille:

https://coderanch.com/t/599910/GUI/java/include-jpg-Graphic



Paul, do you have an answer to this? I see you didn't even return to that earlier thread. When people give you advice on a forum , they expect that the advice will be applied or at least discussed. Otherwise it's just a waste of time.

Please prove to me that I haven't wasted my time critiquing your code.

edit I think you should go through the guidelines on How To Ask Questions On Java Ranch.
+Pie Number of slices to send: Send
Hey guys,

sorry for not answer your comments.
But I can't handle with your answers.
I think my English is not that good.
I will check for an other forum.

Thank you anyway !
+Pie Number of slices to send: Send
Paul, I'm sure your English is just fine for discussing code here. But it is common for beginners to find that their first attempt at writing a Swing program is a mess. You are not alone -- almost everybody does that. It's just that Swing somehow finds all of the things you aren't very good at, and exposes them mercilessly.

So at this point I think you would be better off to temporarily stop trying to make progress with what you have, and fix the problems that the others have already pointed out. In English we say "Don't put lipstick on a pig"... probably you have a similar expression in your native language.
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Hey Guys,
a have a solution.
But i get the point what you want to tell me.
When I have later another question I hope you still have time for me :-)

Thank You all!
+Pie Number of slices to send: Send
Hey, we always have time for people who want to ask questions here!
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2407 times.
Similar Threads
draw different polygons from a arraylist
GridBagLayout
JTable column disappered when clicked on header
problem drawing polygons.
I have an image class and a game class. I want to display the image onto my game.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:59:34.