Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2008, 10:38 PM
Member
 
Join Date: Nov 2008
Location: Earth
Posts: 14
Rep Power: 0
lordbob75 is on a distinguished road
Send a message via AIM to lordbob75
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-21-2008, 01:53 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,195
Rep Power: 5
Fubarable is on a distinguished road
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!
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-21-2008, 10:11 PM
Member
 
Join Date: Nov 2008
Location: Earth
Posts: 14
Rep Power: 0
lordbob75 is on a distinguished road
Send a message via AIM to lordbob75
Default
well in my experience, the java sun tutorials are next to useless. I will give it a shot though; you never know.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-21-2008, 11:41 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,195
Rep Power: 5
Fubarable is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-22-2008, 08:23 PM
Member
 
Join Date: Nov 2008
Location: Earth
Posts: 14
Rep Power: 0
lordbob75 is on a distinguished road
Send a message via AIM to lordbob75
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?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-22-2008, 09:05 PM
Senior Member
 
Join Date: Sep 2008
Posts: 607
Rep Power: 1
Darryl.Burke is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-23-2008, 05:01 PM
Member
 
Join Date: Nov 2008
Location: Earth
Posts: 14
Rep Power: 0
lordbob75 is on a distinguished road
Send a message via AIM to lordbob75
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?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-23-2008, 05:18 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,195
Rep Power: 5
Fubarable is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-23-2008, 08:08 PM
Senior Member
 
Join Date: Sep 2008
Posts: 607
Rep Power: 1
Darryl.Burke is on a distinguished road
Default
wading? More like drowning.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-24-2008, 02:40 AM
Member
 
Join Date: Nov 2008
Location: Earth
Posts: 14
Rep Power: 0
lordbob75 is on a distinguished road
Send a message via AIM to lordbob75
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...
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 11-24-2008, 02:42 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 3,195
Rep Power: 5
Fubarable is on a distinguished road
Default
This is the only link you'll need:

The Really Big Index

Search this page for any Sun tutorial you want.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ScrollPane Issues.. hanifa AWT / Swing 4 09-11-2008 08:18 AM
JList issues aneesahamedaa AWT / Swing 4 09-10-2008 11:27 PM
iterator issues orchid New To Java 2 08-12-2008 01:43 PM
Issues with Jva I.O Annatar01 New To Java 0 02-08-2008 01:16 AM
Array issues Neo82 New To Java 1 12-31-2007 03:22 AM


All times are GMT +2. The time now is 12:10 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org