This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes move from a position to a new position with animation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "move from a position to a new position with animation" Watch "move from a position to a new position with animation" New topic
Author

move from a position to a new position with animation

Paul muellerl
Greenhorn

Joined: Dec 09, 2012
Posts: 7
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.

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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:

http://www.coderanch.com/t/599910/GUI/java/include-jpg-Graphic
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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:

http://www.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.
Paul muellerl
Greenhorn

Joined: Dec 09, 2012
Posts: 7
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 !
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
looks like he's found a native forum

http://www.java-forum.org/awt-swing-swt/145394-bewegung-2d.html
Paul muellerl
Greenhorn

Joined: Dec 09, 2012
Posts: 7
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!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Hey, we always have time for people who want to ask questions here!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: move from a position to a new position with animation
 
Similar Threads
JTable column disappered when clicked on header
How to include a jpg in a Graphic
problem drawing polygons.
draw different polygons from a arraylist
GridBagLayout