Error message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghostrider
    New Member
    • Jan 2007
    • 34

    #1

    Error message

    I keep getting and error message (<identifier> expected
    myButton.addAct ionListener;). Can anyone point me in the right direction?





    import java.util.*;
    import java.swing.*;
    import java.awt.*;
    import java.event.*;

    public class JRS_WK1 extends JFrame implements ActionListener
    {//1
    JButton myButton;

    public static void main(String[]args)
    {//2
    GUI_JButton_Lis tener buttonGui = new GUI_JBtutton_Li stener();
    buttonGui.go();
    }//1

    //Declare variables
    double a, t, i, p;//variables that will be used
    JLabel amountLb1, termLb1, interestLb1, paymentLb1;//create labels
    JTextField amountTf, termTf, interestTf, paymentsTf;//create text fields
    JButton mybutton;// creats a button
    JFrame myframe = new JFrame();// makes the frame
    JButton myButton = new JButton("Calcul ate");
    myButton.addAct ionListener;
    myFrame.getCont entPane().add(m yButton);
    myFrame.setsize (250,250);
    myFrame.setVisi ble(true);

    //Construction of rows in the panel
    amountLb1 = new JLabel("Princip le");
    termLb1 = new JLabel("Term of loan");
    interestLb1 = new JLabel("Interes t Rate");
    paymentLb1 = new JLabel("Monthly Payment");
    amountTf = new JTextField();
    termTf = new JTextField();
    interestTf = new JTextField();
    paymentTf = new JTextField();
    myButton = new JButton("Calcul ate");

    //Construction of the panel
    myFrame = new JFrame("Mortgag e Calculato");
    myFrame.add(amo untLb1);
    myFrame.add(amo untTf);
    myFrame.add(ter mLb1);
    myFrame.add(ter mTf);
    myFrame.add(int erestLb1);
    myFrame.add(int erestTf);
    myFrame.add(pay mentLb1);
    myFrame.add(pay mentTf);
    myFrame.add(myB utton);

    }//2
  • hirak1984
    Contributor
    • Jan 2007
    • 316

    #2
    where is your actionListener method?

    if you implement an actionListener you have to make an actionListener method,right?

    Originally posted by ghostrider
    I keep getting and error message (<identifier> expected
    myButton.addAct ionListener;). Can anyone point me in the right direction?





    import java.util.*;
    import java.swing.*;
    import java.awt.*;
    import java.event.*;

    public class JRS_WK1 extends JFrame implements ActionListener
    {//1
    JButton myButton;

    public static void main(String[]args)
    {//2
    GUI_JButton_Lis tener buttonGui = new GUI_JBtutton_Li stener();
    buttonGui.go();
    }//1

    //Declare variables
    double a, t, i, p;//variables that will be used
    JLabel amountLb1, termLb1, interestLb1, paymentLb1;//create labels
    JTextField amountTf, termTf, interestTf, paymentsTf;//create text fields
    JButton mybutton;// creats a button
    JFrame myframe = new JFrame();// makes the frame
    JButton myButton = new JButton("Calcul ate");
    myButton.addAct ionListener;
    myFrame.getCont entPane().add(m yButton);
    myFrame.setsize (250,250);
    myFrame.setVisi ble(true);

    //Construction of rows in the panel
    amountLb1 = new JLabel("Princip le");
    termLb1 = new JLabel("Term of loan");
    interestLb1 = new JLabel("Interes t Rate");
    paymentLb1 = new JLabel("Monthly Payment");
    amountTf = new JTextField();
    termTf = new JTextField();
    interestTf = new JTextField();
    paymentTf = new JTextField();
    myButton = new JButton("Calcul ate");

    //Construction of the panel
    myFrame = new JFrame("Mortgag e Calculato");
    myFrame.add(amo untLb1);
    myFrame.add(amo untTf);
    myFrame.add(ter mLb1);
    myFrame.add(ter mTf);
    myFrame.add(int erestLb1);
    myFrame.add(int erestTf);
    myFrame.add(pay mentLb1);
    myFrame.add(pay mentTf);
    myFrame.add(myB utton);

    }//2

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by ghostrider
      I keep getting and error message (<identifier> expected
      myButton.addAct ionListener;). Can anyone point me in the right direction?





      import java.util.*;
      import java.swing.*;
      import java.awt.*;
      import java.event.*;

      public class JRS_WK1 extends JFrame implements ActionListener
      {//1
      JButton myButton;

      public static void main(String[]args)
      {//2
      GUI_JButton_Lis tener buttonGui = new GUI_JBtutton_Li stener();
      buttonGui.go();
      }//1

      //Declare variables
      double a, t, i, p;//variables that will be used
      JLabel amountLb1, termLb1, interestLb1, paymentLb1;//create labels
      JTextField amountTf, termTf, interestTf, paymentsTf;//create text fields
      JButton mybutton;// creats a button
      JFrame myframe = new JFrame();// makes the frame
      JButton myButton = new JButton("Calcul ate");
      myButton.addAct ionListener;
      myFrame.getCont entPane().add(m yButton);
      myFrame.setsize (250,250);
      myFrame.setVisi ble(true);

      //Construction of rows in the panel
      amountLb1 = new JLabel("Princip le");
      termLb1 = new JLabel("Term of loan");
      interestLb1 = new JLabel("Interes t Rate");
      paymentLb1 = new JLabel("Monthly Payment");
      amountTf = new JTextField();
      termTf = new JTextField();
      interestTf = new JTextField();
      paymentTf = new JTextField();
      myButton = new JButton("Calcul ate");

      //Construction of the panel
      myFrame = new JFrame("Mortgag e Calculato");
      myFrame.add(amo untLb1);
      myFrame.add(amo untTf);
      myFrame.add(ter mLb1);
      myFrame.add(ter mTf);
      myFrame.add(int erestLb1);
      myFrame.add(int erestTf);
      myFrame.add(pay mentLb1);
      myFrame.add(pay mentTf);
      myFrame.add(myB utton);

      }//2
      In
      Code:
       myButton.addActionListener;
      addActionListen er is a method which takes an ActionListener as an Argument. An ActionListener is any class that implements the ActionListener interface. In your code, the class JRS_WK1 implements ActionListener interface so you can use

      Code:
      myButton.addActionListener(this);
      . Then you would have to write the actionPerformed method in that class because implementing an interface means means that yiou are going to provide all the methods of that interface.

      Comment

      • ghostrider
        New Member
        • Jan 2007
        • 34

        #4
        Ok, I tried the (this) thing and still getting the error message. I'm new to this so it is going to take a few tries to get it right!

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by ghostrider
          Ok, I tried the (this) thing and still getting the error message. I'm new to this so it is going to take a few tries to get it right!
          Did you try all that I suggested? After adding the this thing I told you to do something else after that.

          Comment

          Working...