• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Animation not showing up

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i'm trying to move a circle on a Jform but the circle is not showing up. Below my code. I want to make it possible in the future to call several animations from this class.


 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't test it at the moment, but first two remarks:

in your ActionListener (in MoveRight), you create a New DrawPanel every time the timer fires. Just one DrawPanel suffices...

You  do  not set any preferredSize for Draw panel

See if that helps.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don' t think you need any DrawPanels do you?
Why not just do the drawing in the paintComponent of the Anim class?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why have you got an action listener as a local variable in the constructor? Why are you starting the timer in the constructor and stopping it in the action listener? You appear to want the circle to move 100 to the right every 0.5″. That means that after 8″ it will have disappeared off the right side of your screen, never to be found again. Try moving the circle by smaller distances.
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:I don' t think you need any DrawPanels do you?
Why not just do the drawing in the paintComponent of the Anim class?


OP might be using a ButtonPanel as well in Anim. That's not unusual.

Campbell Ritchie wrote:Why have you got an action listener as a local variable in the constructor?


Can you elaborate a little why that would be a problem, since only the timer needs to access it?
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:. . .  since only the timer needs to access [the action listener]?

Good point. I forgot that Timers can fire action listeners. Put that down as my mistake
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No mistake! And I'm glad you raised the point. In java 8, one would probably do something like:


and for those doing their OCAJP (like me)  it is interesting to know what the difference is compared to using a local ActionListener. No doubt they have some very nasty questions about  this.   .
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic