Java Program to Make a Simple Calculator Using AWT

Hello everyone, in this program I am going to share a code to make a simple calculator in java using awt. This calculator works on two integer numbers. As you enter two numbers and then click on desired button, the result is shown in Result text field. When you will click on Cancel button, the calculator will be closed. So just go through the code and try it. If you have any difficulty in understanding or using the code, then you ask by commenting below.

 

 

Java Program to Make a Simple Calculator Using AWT

 

Category: AWT

12 thoughts on “Java Program to Make a Simple Calculator Using AWT

    1. Neeraj Mishra

      AWT is one of the way to do GUI programming in java. It is a package that contains all classes and interface that are needed to implement GUI. I hope you understand what i want to say.
      Thanks for your valuable comment.

      Reply
  1. muhammad nasir

    It gives this error message not compiling
    The method addActionListener(ActionListener) in the type Button is not applicable for the arguments (Calculator) Calculator.java
    Gives error at this part:
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    b4.addActionListener(this);
    b5.addActionListener(this);

    Reply
    1. nagaraju chandu

      It gives this error message not compiling
      The method addActionListener(ActionListener) in the type Button is not applicable for the arguments (Calculator) Calculator.java
      thi part error plz tell the resone,I am wait for result so do fast .
      Gives error at this part:
      b1.addActionListener(this);
      b2.addActionListener(this);
      b3.addActionListener(this);
      b4.addActionListener(this);
      b5.addActionListener(this);

      Reply ↓

      Reply
    1. Supreet

      modify main as

      public static void main(String args[])
      {
      calculator cal=new calculator();

      cal.addWindowListener(new WindowAdapter()
      {
      public void windowClosing(WindowEvent e)
      {
      System.exit(0);
      }
      });
      }

      and in imports add

      import java.awt.event.WindowListener;

      Reply
  2. zubi

    What is “This” , error occur at this part ,plz help me….!!!

    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    b4.addActionListener(this);
    b5.addActionListener(this);

    Reply
    1. bhargav

      no its right if you have cut pasted the code you should change that comment section

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *