Results 1 to 11 of 11
  1. #1
    lordbob75 is offline Member
    Join Date
    Nov 2008
    Location
    Earth
    Posts
    14
    Rep Power
    0

    Unhappy [SOLVED] MouseMotion Issues

    Ok so I am still just learning JAVA programming, but I do have some experience with programs. I am attempting to write an Applet that has a rectangle or something follow the mouse around. I have not actually gotten a whole lot written yet, just like 20 lines or so.

    What i am having problems with (this is probably really simple...) is getting the mousemotionlistener to work. This is the code i have so far. I will underline where the errors are.


    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.JApplet;
    import javax.swing.JFrame;


    public class moveTest extends JApplet implements MouseMotionListener
    {
    public static void main(String[] args)
    {
    JFrame mover = new JFrame();
    mover.addMouseMotionListener(f);
    mover.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    mover.setSize(400,400);
    mover.setLocation(200,200);
    mover.setVisible(true);
    }

    public void mouseDragged(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }

    public void mouseMoved(MouseEvent arg0) {
    // TODO Auto-generated method stub

    }
    }


    how do i fix this error? I am sure i need to put something in place of f. i just dont know what

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

    Default

    Well, the method is called "addMouseMotionListener". So it makes sense (at least to me) that "f" should be a MouseMotionListener object, right? If I were in your shoes and I didn't know much about this animal, I'd go to the Sun tutorials, press the "Really Big Index" button and search on how to write listeners. There you will find your answer and more. Good luck!

  3. #3
    lordbob75 is offline Member
    Join Date
    Nov 2008
    Location
    Earth
    Posts
    14
    Rep Power
    0

    Default

    well in my experience, the java sun tutorials are next to useless. I will give it a shot though; you never know.

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

    Default

    Quote Originally Posted by lordbob75 View Post
    well in my experience, the java sun tutorials are next to useless. I will give it a shot though; you never know.
    They may seem useless at first, but with time, as you gain more knowledge, you will find them to be nearly indispensable. The only way to get to this level is to keep at it, to keep studying them. Do this and you will thank me later.

  5. #5
    lordbob75 is offline Member
    Join Date
    Nov 2008
    Location
    Earth
    Posts
    14
    Rep Power
    0

    Default

    Well thanks for the tips. I haven't had a chance to work on it since Thursday (school) but I should get some in Monday. So maybe it is just my inexperience but those javasun tutorials just never make sense to me. Maybe it is just because I don't understand it well enough?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    Maybe you tried to dive in the deep end of the tutorials witout going through the more basic ones. A tutorial is just that: a learning resource. It's not a quick reference.

    Once you know the basics, you'll find reading the API will solve most problems.

    db

  7. #7
    lordbob75 is offline Member
    Join Date
    Nov 2008
    Location
    Earth
    Posts
    14
    Rep Power
    0

    Default

    Ok thanks for the tips. Just out of curiosity, I looked at the tutorial for mouse motion listeners, and there were a lot of wierd classes in it like show guiboot and stuff... Is that all necessary? Maybe someone could explain how all that stuff works?

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

    Default

    Hm, maybe we're not looking at the same demo. The one I saw was called MouseEventDemo.java and it used just one other class called BlankArea.java. I didn't see any other classes such as "guiboot".

    If you're talking about the methods createAndShowGUI() and such, then 1) yes you need to use something like this, and 2) if you don't understand it, then you're wading too deep into the Swing tutorial pool and should back up to one of the earlier Swing tutorials.
    Last edited by Fubarable; 11-23-2008 at 05:20 PM.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    wading? More like drowning.

  10. #10
    lordbob75 is offline Member
    Join Date
    Nov 2008
    Location
    Earth
    Posts
    14
    Rep Power
    0

    Default

    yes that is the right one. Would going back and reading through all those tutorials help? Could someone provide me a link to the tutorials? I never can actually find them...

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

    Default

    This is the only link you'll need:

    The Really Big Index

    Search this page for any Sun tutorial you want.

Similar Threads

  1. JList issues
    By aneesahamedaa in forum AWT / Swing
    Replies: 7
    Last Post: 12-15-2009, 04:16 PM
  2. ScrollPane Issues..
    By hanifa in forum AWT / Swing
    Replies: 4
    Last Post: 09-11-2008, 08:18 AM
  3. iterator issues
    By orchid in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 01:43 PM
  4. Issues with Jva I.O
    By Annatar01 in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 01:16 AM
  5. Array issues
    By Neo82 in forum New To Java
    Replies: 1
    Last Post: 12-31-2007, 03:22 AM

Posting Permissions

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