DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    5

    Wink Need help whit MouseEvent...and MouseListener...

    ok i was trying to do an Hovering method... which was looking like this:
    Code:
    	public void method4(String s, int x1, int y1, int x2, int y2, int x3, int y3)
    	{
    		try{
    			Image i;
    			Graphics g = frame.getGraphics();
    			Graphics2D g2 = (Graphics2D)g;
    			i = ImageIO.read(new File("./Image/"+s));
    			frame.addMouseListener(ML);
    			if(anInt1 >= x1 + x2 || anInt1 <= x1 - x2 && anInt2 >= y2 + y1 || anInt2 <= y2 - y1){
    			g2.drawImage(i, x3, y3, x2, y2, frame);
    			println("Image "+s+"has sucessfully hovered");
    			}
    			}catch (Exception e){
    			println("Error while loading hovering Image "+s+"");
    			}
    	}
    but it didnt work when i pass my mouse on the image... i was getting the mouseX and mouseY position from the method mouseMoved :

    Code:
    	public final void mouseMoved(MouseEvent event){
    	int i = event.getX();
    	int j = event.getY();
    	anInt1 = i;
    	anInt2 = j;
    	}
    ... i dont know what is missing but there is surely something missing...
    note : the problem is not from the method, its just that my method mouseMoved doesnt work so i guess my MouseListener doesnt work but why?

    if anyone know what am I missing I would very appreciate you tell me

    And dosrry for my bad english... im french

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    If you want to listen for mouse motion, why not use a MouseMotionListener - take a look at this page of the Java Tutorial:

    http://java.sun.com/docs/books/tutor...nlistener.html

    and while you're there you can get some help with other event handling code you might be interested in.

  3. #3
    Join Date
    Sep 2009
    Posts
    5
    finally someone that take time to answer, thanks you very much

    Mousemotionlistener worked perfectly

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links