Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java Applet Shooter click timings/limit

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Applet Shooter click timings/limit

    Hi
    I'm doing a shooter game for a project at school.
    I've got it set to detect when I click the mouse and where the x and y co-ordinates of the cursor is.
    It also detects a mouse drag, dragging is fine because at the end I have a sleep command with the time based on the weapon.
    However I don't know what I can do with the mouse clicked one.
    Puting a sleep statement at the start would just put a delay between my clicks and firing and at the end would do nothing.
    I have quite a few hundred lines of code and I don't really want to spend hours changing everything, I also know nothing about multi-threading and everything on the internet seems really complicated or I have no idea how to implement it into my code.

    so I want a nice short piece of code i can put into my applet that will limit my mouse clicks to once every 100ms or 700ms(different guns)

    I'm working with BlueJ

    Thanks to anyone who can help


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java Applet Shooter click timings/limit

    It also detects a mouse drag, dragging is fine because at the end I have a sleep command with the time based on the weapon.
    Not sure what this means or how that could be "fine," whatever that means.
    I've got it set to detect when I click the mouse and where the x and y co-ordinates of the cursor is . . . I don't know what I can do with the mouse clicked one.
    These statements seem contradictory. What are you saying?
    so I want a nice short piece of code i can put into my applet that will limit my mouse clicks to once every 100ms or 700ms(different guns)
    As you've already suggested, this is not done by sleeping the thread.

    You have several hundred lines of code, and you want someone to give you a few simple lines that do what you describe (whatever that is) and just fit right into what you have without the author even seeing what the lines are being fit into? Does that seem reasonable to you?

    If you haven't already, you need to learn how to use Timers. A small, simple game loop could be used to accomplish what you want done when you want them done. Perhaps all you want can be done with one or a few Timers, but it's hard to say. I can understand not wanting to extensively change what you have, especially if it's due soon. Sometimes we squeeze ourselves into tight spots because of unreasonable, self-determined limitations, assumptions, looming deadlines, or misplaced code affection.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Applet Shooter click timings/limit

    I can see how that was hard to understand.
    I apologize I'm very new to Java and this is my first time posting anything on these forums.
    I have no idea what timers are or how you use them.
    Could you please link me to something explaining, possibly with an example?

    I need to limit the amount of times my code can run "public void mouseClicked(MouseEvent e)" in a short amount of time.
    Everything in this method is what does the shooting in the game.
    but you can just keep pressing the mouse button and shoot way faster then I would like.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java Applet Shooter click timings/limit

    The Oracle tutorials are always a great place to start. Start by using your favorite search engine to search something like: java timer tutorial. In many cases, one of the first results will include "oracle" in the address, and might be titled "How to Use Swing Timers."

    There are many, many, many examples of how to do simple animation and control in Java Applets. Again, using your favorite search engine properly fed will yield many results.

    Good luck and come back when you need help with specific elements of your project.

Similar Threads

  1. 65535 bytes java limit
    By xpoiled7 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: August 30th, 2013, 10:03 PM
  2. How to create a Right Click Menu for a Text Field in Java?
    By deamon0 in forum AWT / Java Swing
    Replies: 1
    Last Post: July 18th, 2013, 11:20 PM
  3. Java integer limit
    By jobi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 4th, 2013, 03:27 PM
  4. Need a java code to click similar buttons on a web page
    By kalawadh in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2013, 12:23 PM
  5. Directly Click the pdf File and my Java application will run
    By Jhovarie in forum Java Theory & Questions
    Replies: 2
    Last Post: May 3rd, 2011, 08:48 AM

Tags for this Thread