2 Replies - 433 Views - Last Post: 08 April 2012 - 01:23 PM Rate Topic: -----

#1 Crimson Wings  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 215
  • Joined: 11-July 09

mouseDragged not Implemented?

Posted 08 April 2012 - 01:07 PM

I'm certain this code is supposed to work because I AM implementing the mouseDragged method. Can someone tell me why this code:

Is giving me this error message:

/*7.- Cree un applet que contenga algun elemento grafico. Inventelo Ud. mismo, haga trabajar su imaginacion y sorprenda a su docente  con alguna buena idea que se le ocurra. A continuacion se
muestra una tabla que contiene metodos graficos que puede emplear.*/

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;

public class Siete extends JApplet
{

	int corXPunto;
	int corYPunto;

	public void init()
	{
		JLabel instrucciones = new JLabel("Haga click en cualquier lado, y mueva el mouse arriba o abajo para girar el pivote.");
		getContentPane().setSize(500, 500);
		instrucciones.setBounds(2, 2, 800, 10);
		getContentPane().setLayout(null);
		getContentPane().add(instrucciones);
		corXPunto = 150;
		corYPunto = 150;
		getContentPane().addMouseMotionListener(new MouseMotionListener() //The error occurs here
		{
			public void mouseDragged(ActionEvent e)
			{
			}
		});
	}
	
	public void paint(Graphics g)
	{
		super.paint(g);
		g.drawOval(130, 20, 200, 200);
		g.fillOval(corXPunto, corYPunto, 20, 20);
	}
}


Quote

The abstract method "void mouseDragged(java.awt.event.MouseEvent);" inherited from type "java.awt.event.MouseMotionListener is not implemented in the non abstract class "Siete"


?

I have been writing events like this since the teacher started "teaching" us Java but for some reason I can't get mouse events to work. Any help fixing this will be highly appreciated. I have been scratching my head for 30 minutes now.

This post has been edited by Crimson Wings: 08 April 2012 - 01:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: mouseDragged not Implemented?

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1414
  • View blog
  • Posts: 3,136
  • Joined: 05-April 11

Re: mouseDragged not Implemented?

Posted 08 April 2012 - 01:17 PM

You are not overriding the method mouseDragged (as it tells you)

You wrote
public void mouseDragged(ActionEvent e)



Should be
public void mouseDragged(MouseEvent e)



You should go lookup the method in the API, if you are not sure what it looks like
Was This Post Helpful? 2
  • +
  • -

#3 Crimson Wings  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 215
  • Joined: 11-July 09

Re: mouseDragged not Implemented?

Posted 08 April 2012 - 01:23 PM

Thanks a bunch. Your fix worked, but I also had to add public void mouseMoved.
+1
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1