• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Not able to compile

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Trailboss
Posts: 23866
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. It worked and thank you very much.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic