• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to compile

 
Thunthu Ganapathy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class MouseEvents extends Applet
implements MouseListener, MouseMotionListener{
String msg="";
int mouseX = 0, mouseY = 0;
public void init() {
addMouseListener(this);
addMouseMotionListener(this);
}

public void mouseClicked(MouseEvent me) {
mouseX=0;
mouseY=10;
msg = "Mouse Clicked.";
repaint();
}

public void paint(Graphics g) {
g.drawString(msg, mouseX, mouseY);
}
}
Getting an error saying class MouseEvents must be declared abstract.
Could anyone throw some light on this?. Looks like the Interface is not getting implemented. How do I overcome this?.
Thanks,

[This message has been edited by Thunthu Ganapathy (edited May 10, 2000).]
 
paul wheaton
Trailboss
Pie
Posts: 21887
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implementing MouseListener and MouseMotionListener requires that you implement a whole bunch of methods. You have implemented only one. Therefore, your class must be declared abstract (and inheriting classes will implement the rest of the methods) or you must implement the rest of the methods.
 
Thunthu Ganapathy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I could compile the program after making the class abstract. While invoking through appletviwer I am getting an error saying can't be instantiated.
Could you please help me.
Thanks,
 
Pawel Veselov
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to implement this methods, just make them empty ! If you switch to abstract class you'll be not able to instantiate it! No of abstract classes can be instantiated at all.
So , add :
public void mouseDragged(MouseEvent e) {}
....
for each method that is abstract in both MouseListener and MouseMotionListener classes.
 
Thunthu Ganapathy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. It worked and thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic