Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JFrame;
- import javax.swing.JTextField;
- public class Main extends JFrame{
- private JTextField txtf1;
- private JTextField txtf2;
- private JTextField txtt;
- private double a;
- private double b;
- private double sum;
- public static void main(String[] args) {
- Main go = new Main();
- go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- go.setSize(500,400);
- go.setVisible(true);
- }
- public Main(){
- super("Title window");
- txtf1 = new JTextField(10);
- txtf2 = new JTextField(10);
- txtt = new JTextField(10);
- setLayout(new FlowLayout());
- add(txtf1);
- add(txtf2);
- add(txtt);
- txtf2.addActionListener(
- new ActionListener() {
- public void actionPerformed(ActionEvent event) {
- a = Double.parseDouble(txtf1.getText());
- b = Double.parseDouble(txtf2.getText());
- sum = a + b;
- txtt.setText(Double.toString(sum));
- }
- }
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement