java problem, need help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frozzenn
    New Member
    • Oct 2007
    • 6

    java problem, need help please

    I'm getting this message:
    "C:\Documen ts and Settings\Evalda s\Desktop\moksl as\JAVA 2kursas\L2\cube method.java:5: class L2cubemethod is public, should be declared in a file named L2cubemethod.ja va
    public class L2cubemethod extends Applet implements ActionListener"

    Can please someone explain whats wrong with this program?:

    [CODE=java]import java.applet.App let;
    import java.awt.*;
    import java.awt.event. *;

    public class L2cubemethod extends Applet implements ActionListener
    {
    Label lblnumber;
    TextField tfnumber;

    int number;
    int cube;

    public void init()
    {
    lblnumber = new Label( " Enter your number and press Enter:");
    add(lblnumber);

    tfnumber = new TextField(10);
    add(tfnumber);

    cube = 0;

    tfnumber.addAct ionListener(thi s);
    }


    public void actionPerfomed( ActionEvent e)
    {
    number = Integer.parseIn t(e.getActionCo mmand() );

    cube = number*number*n umber;
    tfnumber.setTex t("");
    showStatus ( Integer.toStrin g( cube) );
    }
    }[/CODE]
    Last edited by Ganon11; Oct 13 '07, 03:05 PM. Reason: Please use the [CODE] tags provided.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    It seems you have saved the file an improper name. You should have saved your file as "L2cubemethod.j ava" typed exactly that way.

    Comment

    • frozzenn
      New Member
      • Oct 2007
      • 6

      #3
      Originally posted by Ganon11
      It seems you have saved the file an improper name. You should have saved your file as "L2cubemethod.j ava" typed exactly that way.
      C:\Documents and Settings\Evalda s\Desktop\moksl as\JAVA 2kursas\L2\L2cu bemethod.java:5 : L2cubemethod is not abstract and does not override abstract method actionPerformed (java.awt.event .ActionEvent) in java.awt.event. ActionListener
      public class L2cubemethod extends Applet implements ActionListener
      ^
      1 error

      Tool completed with exit code 1

      I think file name I saved is the same:" L2cubemethod.ja va" still get this message. Im so tired of this. Any other suggestions?

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        OK, this is an entirely new error. In this one, just read the text: You say your class implements ActionListener. Well, one of the requirements for saying your class implements ActionListener is to provide a method called actionPerformed that accepts an ActionEvent parameter - which you must not have done.

        EDIT: Then again, maybe you did.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by Ganon11
          ...

          EDIT: Then again, maybe you did.
          He did not. He got the spelling for actionPerformed wrong.

          Comment

          • frozzenn
            New Member
            • Oct 2007
            • 6

            #6
            Originally posted by r035198x
            He did not. He got the spelling for actionPerformed wrong.

            Thank you very much guys. Spend hours looking for error. And it was just spelling. Thank you.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by frozzenn
              Thank you very much guys. Spend hours looking for error. And it was just spelling. Thank you.
              Keep it in mind: when your class is not abstract and the compiler is whining that
              it should be abstract it also tells you the methods that need be implemented from
              either an abstract parent class or an implemented interface. If you think you *did*
              do so, you've made a typo in at least on of those methods.

              The compiler can't pinpoint you to the line where you made a mistake because
              you have all the rights to implement *other* methods with names you picked.

              kind regards,

              Jos

              Comment

              Working...