Results 1 to 8 of 8
  1. #1
    theunlockeRRR is offline Code Child
    Join Date
    Aug 2016
    Location
    Serbia
    Posts
    45
    Rep Power
    0

    Question Proper way of adding animations?

    What is the best way to create animations for buttons. I added button image with g2d drawImage. Made an mousePressed and the button works. But how can i add effects to the button when i hover on the button? Like draw a rect around the button or something like that. I tried doing it with mouseEntered but it does not work.

  2. #2
    theunlockeRRR is offline Code Child
    Join Date
    Aug 2016
    Location
    Serbia
    Posts
    45
    Rep Power
    0

    Default Re: Proper way of adding animations?

    B.u.m.p.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Proper way of adding animations?

    What toolkit are you using? AWT / Swing / SWT / JavaFX / something else I haven't even heard of?

    Note that each of those toolkits have a separate section on these forums, where you can get better responses to a specific question.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    theunlockeRRR is offline Code Child
    Join Date
    Aug 2016
    Location
    Serbia
    Posts
    45
    Rep Power
    0

    Default Re: Proper way of adding animations?

    Quote Originally Posted by DarrylBurke View Post
    What toolkit are you using? AWT / Swing / SWT / JavaFX / something else I haven't even heard of?

    Note that each of those toolkits have a separate section on these forums, where you can get better responses to a specific question.

    db
    I am using Swing. I've managed to add animations for moving the buttons from left to right using swing Timers. But I can't get mouse hovering to work. I added a MouseListener, made a new Mouse Adapter, mousePressed works but mouseEntered does not.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Proper way of adding animations?

    From the API documentation on AbstractButton (subclassed by JButton) for setRolloverEnable(boolean b).

    "Sets the rolloverEnabled property, which must be true for rollover effects to occur. The default value for the
    rolloverEnabled property is false. Some look and feels might not implement rollover effects; they will ignore this property."

    So I recommend you implement your own button and modify the images as appropriate.


    Regarding b.u.m.p.

    Be patient - one to three days is not being patient. (Of the questions I have asked on this forum, several have never been answered).
    I simply assume that the answer is not readily known. If someone knows it, they will probably respond.

    Regards,
    Jim
    Last edited by jim829; 08-22-2016 at 05:03 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    theunlockeRRR is offline Code Child
    Join Date
    Aug 2016
    Location
    Serbia
    Posts
    45
    Rep Power
    0

    Default Re: Proper way of adding animations?

    So you are saying that it's best that I make my own method for drawing buttons with images, then extend JButton and add rollover?

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Proper way of adding animations?

    Quote Originally Posted by theunlockeRRR View Post
    So you are saying that it's best that I make my own method for drawing buttons with
    images, then extend JButton and add rollover?
    That's what I would do. I could not get it to work as advertised. One poster on SO said it was a known problem.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Proper way of adding animations?

    Thread moved to AWT/Swing.

    Read through the API for AbstractButton and note down how many setXxxIcon methods you find, and what each does.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Question about drawing animations in Java (SWT)
    By instop in forum New To Java
    Replies: 1
    Last Post: 04-22-2014, 05:28 PM
  2. animations with java?
    By shujisan87 in forum New To Java
    Replies: 3
    Last Post: 09-13-2011, 04:09 PM
  3. Animations not refreshing
    By zshaw in forum New To Java
    Replies: 1
    Last Post: 12-26-2010, 12:05 AM
  4. Graphics/animations etc. Where to begin?
    By Mattedatten in forum New To Java
    Replies: 2
    Last Post: 03-16-2010, 05:51 PM
  5. SWT Animations Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 06-28-2008, 09:23 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
  •