
Sir,
How show sum of two tex boxes data to third box

Answer

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class SumOfNumbers{
public static void main(String[] args){
JFrame f=new JFrame();
JLabel label1=new JLabel("First Number: ");
JLabel label2=new JLabel("Second Number: ");
JLabel label3=new JLabel("Result: ");
final JTextField text1=new JTextField(20);
final JTextField text2=new JTextField(20);
final JTextField text3=new JTextField(20);
JButton button=new JButton("Calculate");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int num1=Integer.parseInt(text1.getText());
int num2=Integer.parseInt(text2.getText());
int result=num1+num2;
text3.setText(Integer.toString(result));
}
});
JPanel p=new JPanel(new GridLayout(4,2));
p.add(label1);
p.add(text1);
p.add(label2);
p.add(text2);
p.add(label3);
p.add(text3);
p.add(button);
f.add(p);
f.setVisible(true);
f.pack();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.