Perry Smith

Java Questions & Answers

Home / Java Q & A Page 2 / Java Q & A Archive Main Page

 Almost there...
 Monday, 07-Dec-98 14:43:37

      206.215.24.95 writes:

      Dear Mentor(s)

      Well, I feel progress is being made. Only one error showed up this time. However, I
      still can't figure out what the resolution is. It looks like the compiler can't
      find the method "mouseClicked."

      Scott, thanks for all your help. As a teacher I know you can be frestrated by students
      not trying to find the answers to their own questions. Well I looked in the Java
      Platform 1.1 Core API Specification for help on this issue, but no luck.

      I think when I get this one compiled I'm going to throw a party.

      Thanks,

      Kim
      --------------------------------------------
      import java.awt.*;
      import java.awt.event.*;
      import java.applet.*;

      public class ClickHere extends Applet implements MouseListener
      {
      String DisplayString = new String ("Click Here");

      public void init () {
      addMouseListener(this);
      System.out.println("Welcome to ClickHere!");
      }

      public void paint(Graphics g) {
      g.setColor( Color.blue );
      g.drawRect( 0, 0, 150, 80 );
      g.drawString( DisplayString, 50, 20 );
      }

      public void mouseClicked (MouseEvent evt, int x, int y) {
      showStatus("Welcome to ClickHere!");
      DisplayString = "Thank You";
      repaint();
      }

      public void mouseEntered (MouseEvent evt) {}
      public void mouseExited (MouseEvent evt) {}
      public void mousePressed (MouseEvent evt) {}
      public void mouseReleased (MouseEvent evt) {}
      }
      --------------------------------------------
      ClickHere.java:5: class ClickHere must be declared abstract. It does not define
      void mouseClicked(java.awt.event.MouseEvent) from interface java.awt.event.Mouse
      Listener.
      public class ClickHere extends Applet implements MouseListener
      ^
      1 error


      Kim


Response
 Re: Almost there...
 Monday, 07-Dec-98 17:01:57

      148.5.110.65 writes:

      Kim,

      Note the compiler's error listing:
      ClickHere.java:5: class ClickHere must be declared abstract. It does not define
      void mouseClicked(java.awt.event.MouseEvent)

      It is expecting a method -
      public void mouseClicked(MouseEvent evt) (the parameter name doesn't matter). Yours
      is defined - ...mouseClicked(MouseEvent evt, int x, int y) with extra parameters. As
      far as Java is concerned, your function is totally different from the the one it
      is looking for. You have extra parameters. You can get the x and y from the MouseEvent.


      Scott

      Scott_M,



Home / Java Q & A Page 2 / Java Q & A Archive Main Page