Advertisement
Guest User

Untitled

a guest
May 6th, 2021
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. public class Question extends Applet implements ActionListener
  5. {
  6.    TextField firstNum, secondNum, resultNum;
  7.    public Question()
  8.    {                      
  9.       setLayout(new GridLayout(3, 2, 10, 15));  
  10.       setBackground(Color.cyan);
  11.  
  12.       firstNum = new TextField(15);
  13.       secondNum = new TextField(15);
  14.       resultNum = new TextField(15);
  15.  
  16.       secondNum.addActionListener(this);
  17.  
  18.       add(new Label("Enter First Number"));  
  19.       add(firstNum);
  20.       add(new Label("Enter Second Number"));
  21.       add(secondNum);
  22.       add(new Label("S U M"));              
  23.       add(resultNum);
  24.    }
  25.    public void actionPerformed(ActionEvent e)
  26.    {                        
  27.       String str1 = firstNum.getText();
  28.       double fn = Double.parseDouble(str1);
  29.       double sn = Double.parseDouble(secondNum.getText());
  30.  
  31.       resultNum.setText("Sum is " + (fn+sn));
  32.    }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement