Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    76

    Unanswered: Override abstract method mouseExited

    I am getting following error at the time of compilation of java code

    D:\JAVAPRG>javac MouseClickExample.java
    MouseClickExample.java:5: MouseClickExample is not
    abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.Mouse
    Listener
    public class MouseClickExample extends Applet implements MouseListener

    Code as under
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class MouseClickExample extends Applet implements MouseListener
    {
    int xpos;
    int ypos;

    int rect1xco, rect1yco, rect1width, rect1height ;
    boolean mouseEntered;
    boolean rect1Clicked;

    public void init()
    {
    rect1xco = 20;
    rect1yco = 20;
    rect1width = 100;
    rect1height = 50;
    addMouseListener(this);
    }

    public void paint(Graphics g)
    {
    g.setColor(Color.green);
    g.fillRect(rect1xco,rect1yco,rect1width,rect1heigh t);
    g.setColor(Color.red);
    g.drawString("("+xpos+"."+ypos+")",xpos,ypos);
    if (rect1Clicked)g.drawString("You clicked in the rectangle",20,120);
    else g.drawString("Mouse is the outside of applet area",20,160) ;
    }

    public void mouseClicked(MouseEvent me)
    {
    xpos = me.getX();
    ypos = me.getY();

    if (xpos > rect1xco && ypos < rect1xco+rect1width && ypos > rect1yco && ypos < rect1yco+rect1height) rect1Clicked = true ;
    else
    rect1Clicked = false ;
    repaint();
    }

    public void mouseReleased (MouseEvent me)
    {
    }

    public void mouseEntered (MouseEvent me)
    {
    mouseEntered = false;
    repaint();
    }
    }

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    And your question is?

  3. #3
    Join Date
    Dec 2003
    Posts
    51

    Re

    just add these methods to avoid compilation error.. and proceed......

    /////////////////////////////////////////
    public void mouseExited(MouseEvent e)
    {

    }

    public void mousePressed(MouseEvent e)
    {
    }
    /////////////////////////////////////////

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •