Question: MouseMotionListener and Runnable???


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Question: MouseMotionListener and Runnable???

  1. #1
    Join Date
    Jun 2005
    Posts
    4

    Question: MouseMotionListener and Runnable???

    I'm working on several programs , and trying to merge them...

    One program implements MouseMotionListener, and updates a game paddle at the bottom of my animation scene.

    Another program implements Runnable, and a continuous loop inside RUN() bounces a ball around the screen.

    My question is, how come I can't implement MouseMotionListener AND Runnable in the same program, when I try to do it, nothing works!!!

    I can provide source if you desire, but an applet that works the way i want it so far can be found on this web site:

    http://www.jeffpowerweb.bravehost.com

    The applet that is there implements MouseMotionListener, and the animation only takes place when mouseMoved is called.

    What I want is for a separate thread (or all the animation could take place in the same thread, that's ideal...) to animate a ball that bounces around the screen...I can figure the rest out, I'm making a breakout game.

    Later and thank you, if you can help me,

    Jeff C

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    MouseMotionListener and Runnable should work perfectly together, you must have set
    it up wrong, so you should post the code.
    eschew obfuscation

  3. #3
    Join Date
    Jun 2005
    Posts
    4
    Ok, this was my latest attempt, I put everything in the run() function.

    Will the mouseMoved() event, when triggered, interrupt a thread?

    It shouldn't...right?

    The applet doesn't seem to get off the ground, I've attached the source, graphics files, and sampling html file to test run the applet.

    Thanks,

    Jeff C

    PS. Do you have any sample source code of these two interfaces working together, I would appreciate it very much at this point, but I'm still looking to get it to run correctly.
    ]
    PPS, when I do finally get it, i'll post the source code here too.
    Attached Files Attached Files

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Cool That was quite an exotic approach...

    I have restructured your applet, there was a lot of things to change, but
    instead of me spending time going into every detail I suggest that you
    have a good look at what I've done here.
    Basically I've divided the applet into methods that enables the correct
    sequential processing that an imageLoading & animated applet is supposed to.

    Note: a sleep(5) during the animation gives 200 ticks per second, ...how fast
    is your screen/eyes ...... You will have to reconsider that.

    I haven't tested it though, but I suspect that you have some more tweaking to do here.
    Attached Files Attached Files
    eschew obfuscation

  5. #5
    Join Date
    Jun 2005
    Posts
    4

    Talking Awesome, thank you!!!

    Your code worked.

    not at first...there was a misspelling imageloader and imageLoader didn't match up...

    ...and the backg image was created originally to fill the entire screen, so I fixed that using getScaledInstance.

    You are awesome, I will update you in this forum as to my progress.

    Here is the final updated at this stage...I will still need to study your code so more also. That package thing was cool too, but I commented it out so my usual directory was updated, not the new package one.

    Later,

    Jeff C
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center