Java GUI Program to Add Two Numbers Using AWT

You may also like...

5 Responses

  1. vikas says:

    “b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    int a = Integer.parseInt(tf1.getText());
    int b = Integer.parseInt(tf2.getText());
    int c = a + b;
    l1.setText(“Their sum is = ” + String.valueOf(c)); “”

    if i want to add more than one button such as “add” ,”sub” ,”mul” etc..
    so what is step to add more button

    • dumbitdude says:

      Initialize a new button like:

      Button b2 = new Button(“LABEL OF THE BUTTON”);

      and then set its bounds by using:


      Then finally use


      to include it.

      Eventually, you have to create a new Action Listener Anonymous class

      b2.addActionListener(new ActionListener(){


      and then specify what should happen when you click the button inside a method.

      – Scottshak

  1. July 11, 2017

    […] Also, you could use Java GUI or AWT to make an interesting looking program. I have created an addition program using GUI here. […]

  2. July 12, 2017

    […] How to Add Two Numbers […]

  3. July 13, 2017

    […] a Checkbox in Java GUI is quite a simple process. Here, unlike the buttons we saw in a Java GUI program to add two numbers there is no addActionListener. We have addItemListener instead. Checkbox in Java GUI comes really […]

Leave a Reply