Results 1 to 3 of 3
  1. #1
    Markgm is offline Member
    Join Date
    Nov 2010
    Location
    VT, USA
    Posts
    31
    Rep Power
    0

    Default Adding animation for a series of moves

    Hi,
    I am keeping a deck of cards, as imageIcons in JLabels, as laid out on a JLayeredPane. I have just discovered that moving a card in the event dispatch thread slowly across the screen doesn't have any repainting in it (even with repaint() and vaildate() and all of this).

    I have my existing code. There are various legal play types, and each makes calls to move cards when it is time to make a play. Currently, a move simply changes the location of a card. A single play, however, could involve up to two moves and two flips. I will also want a little animation in the flips. So I am in my playType code, say, and I want to issue a few commands, in series, to cause animation of one thing at a time, then the next, and then done.

    I can't have the user being able to click on anything until the animation is done. I could skip mouse listeners on cards while animation is flagged.

    The thing is, the playType "makePlay()" function is where the controller is. I have a dozen PlayType subclasses, each of which knows a series of moves and flips of its own. Such a controller function needs to be able to issue a series of animation requests (and then be done).

    How should I approach this? Should I make a "List" of moves, and then have those moves being executed by events I fire to myself? Can I make a component of some kind that I just use to fire events to myself? My PlayType classes have no sense of the GUI, and do not have gui controls. They reference the "board[][]", which has rows and columns of CardStack objects. Then their makePlay() and makeReversePlay() functions make calls to move and flip cards.

    TIA, and cheers -
    Mark

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    Should I make a "List" of moves,
    Sounds good.

    and then have those moves being executed by events I fire to myself?
    See How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features). Each time the Timer fires you invoke the next move.

  3. #3
    Markgm is offline Member
    Join Date
    Nov 2010
    Location
    VT, USA
    Posts
    31
    Rep Power
    0

    Default

    Thank you for the link. That is funny. I must have thought a timer was not something to look at, because I tried adding a call to Thread.sleep(), and that didn't work. It really did spend a second moving the location of card across the screen - it just didn't paint.

    Hey, I can get an event from a timer. It runs in a timer thread. I can practically use the same code (but not in a loop) to move one card.

    Thanks again -
    Mark

Similar Threads

  1. Alternating between players moves in a game
    By nephos in forum New To Java
    Replies: 3
    Last Post: 04-18-2011, 08:39 AM
  2. Replies: 6
    Last Post: 01-31-2010, 01:44 PM
  3. Bishops moves
    By michail in forum New To Java
    Replies: 5
    Last Post: 01-28-2010, 09:33 PM
  4. Adding popup Menu on animation
    By Peggy in forum Java Applets
    Replies: 2
    Last Post: 12-10-2008, 08:33 AM
  5. Replies: 1
    Last Post: 02-16-2008, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •