Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default quick question about mouseMove()

    So i have in my applet:

    Java Code:
    public boolean mouseMove (Event e, int mx, int my){
    	mousex = mx;
    	mousey = my;
    	return true;
    }
    Is there a way to make it so it only calls synchronized with my thread? Because it calls itself too many times per second, faster then my game´s frames per second.
    Last edited by sgthale; 06-20-2011 at 05:47 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default

    FWIW, that method is deprecated as of java 1.1! Read the API docs on the methods you are using, and use a light weight component and a mouse motion listener, and post an SSCCE that demonstrates the problem

  3. #3
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by doWhile View Post
    FWIW, that method is deprecated as of java 1.1! Read the API docs on the methods you are using, and use a light weight component and a mouse motion listener, and post an SSCCE that demonstrates the problem
    What does deprecated mean? Also what is SSCCE

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by sgthale View Post
    What does deprecated mean?
    It means it is no longer supported and you should use the method that replaces it instead.
    Also what is SSCCE
    What happened when you typed that into Google?

  5. #5
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  6. #6
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    I looked at the tutorial but it only has the mouselistener within the main class for the applet. I want to make it so i have a separate class and it connects WITH the main class.

    but the problem is that i dont know how to do that when i already have a " extends Applet implements Runnable" in my main class

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm sorry, but I don't fully understand your current problem. Could you clarify it a bit, give us more information and even code? The best code would be an SSCCE if possible.

  8. #8
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Unhappy

    Okay so I have in my first main class for my applet:

    Java Code:
    public class Main extends Applet implements Runnable{
           //run, init, start, blah blah blah
    }
    I want to create a separate class to detect mouse coordinates and buttons and stuff and then send that information back to my Main class. But I dont know how to

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Create a class that extends JPanel and have it implement the mouse listener interface.
    Add the methods to that class that are required by the listener interface.
    Add an instance of that class to a container like your JFrame.
    Give that class the focus so it will receive the mouse events.

  10. #10
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Edit: Nrvmd fixed it thanks
    Last edited by sgthale; 07-31-2011 at 02:15 AM.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Shouldn't that be nvrmd?
    What is nrvmd?

  12. #12
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Shouldn't that be nvrmd?
    What is nrvmd?
    yes its nvrmd. just a typo

  13. #13
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default Baah another problem

    So I fixed it but now if I want it to work I have to launch/run it from my MouseListener class instead of my Main class:

    Java Code:
    public class Main extends Applet implements Runnable{
         // init, start, run, blah....
    
    }
    Java Code:
    public class Input extends Main implements KeyListener, MouseMotionListener, MouseListener {
    	public void init(){
    		addKeyListener(this);
    		addMouseMotionListener(this);
    		addMouseListener(this);
    	}
            //other blah blah...
    }
    If i try running the program from my Main class it wont include the Input class.

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    if i want it to work i have to launch it from my MouseListener class instead of my Main class
    What is the "it"? The class Main is an Applet.

    If i try running the program from my Main class it wont include the Input class
    Why are you defining a class as an extension to your Main class?

    What are you putting on the <APPLET tag's CODE= attribute?

    Can you post a small program that compiles and executes and shows the problem. Your small pieces of code don't show enough

  15. #15
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What is the "it"? The class Main is an Applet.


    Why are you defining a class as an extension to your Main class?

    What are you putting on the <APPLET tag's CODE= attribute?

    Can you post a small program that compiles and executes and shows the problem. Your small pieces of code don't show enough

    Okay i made a small program that demonstrates my problem.



    The IT is just my program itself .This is my Main class where I want to just run it and it will run everything and start the game.

    Java Code:
    import java.applet.Applet;
    
    
    @SuppressWarnings("serial")
    public class s extends Applet implements Runnable{
    
    	public void run() {
    	}
    }
    My game has an Input class that detects all the keyboard and mouse actions. This is it:

    Java Code:
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    
    @SuppressWarnings("serial")
    public class Input extends s implements KeyListener {
    	public void init(){
    		super.init();
    		addKeyListener(this);
    	}
    	public void keyPressed(KeyEvent e) {
    		System.out.println("YOU PRESSED A KEY");
    	    e.consume();
    	}
    	public void keyReleased(KeyEvent e) {
    	    e.consume();
    	}
    	public void keyTyped(KeyEvent e) {
    		e.consume();
    	}
    }
    When I try running my program from my Main class it will not incorporate the Input class and thus will not show the "YOU PRESSED A KEY". But if I run it from my Input class it WILL work. I just need my program to work by having it start running from my Main class instead of my Input class.

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    When I try running my program from my Main class it will not incorporate the Input class
    How do you expect it to, There is no reference to the Input class in s class.
    Why do you have the two classes?

  17. #17
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    How do you expect it to, There is no reference to the Input class in s class.
    Why do you have the two classes?
    So how do I make it a reference to Input class?

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Input input = new Input(); // create an instance and get a reference

  19. #19
    sgthale is offline Member
    Join Date
    Apr 2011
    Posts
    48
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Input input = new Input(); // create an instance and get a reference
    Okay but thats for handling it like an Object is there no way to make Input run automatically when the Main class is ran?

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    The browser can only create and call one class. After that it is up to you to create and call the classes you want to use.

Page 1 of 2 12 LastLast

Similar Threads

  1. quick question
    By biggerthanblue in forum New To Java
    Replies: 2
    Last Post: 04-10-2011, 04:33 AM
  2. Quick Question...
    By FatalSylence in forum New To Java
    Replies: 4
    Last Post: 10-15-2010, 02:38 PM
  3. Quick question
    By sAntA199 in forum New To Java
    Replies: 2
    Last Post: 12-09-2009, 03:01 AM
  4. quick question
    By vouslavous in forum Java Applets
    Replies: 4
    Last Post: 04-24-2009, 08:35 PM
  5. Quick Question
    By Spenc in forum New To Java
    Replies: 3
    Last Post: 09-22-2008, 02:26 PM

Tags for this Thread

Posting Permissions

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