TODO SWING SUMA DE DOS NUMEROS

NUEVO EJEMPLO
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class calculadora extends JApplet
{
    JTextField t1=new JTextField(20);
    JTextField t2=new JTextField(20);
    JTextField t3=new JTextField(20);
    JButton suma=new JButton("SUMAR VALORES");
   
    public void init()
    {
        Container c=getContentPane();
        c.setLayout(new FlowLayout());
        c.add(t1);
        c.add(t2);
        c.add(t3);
        suma.setMnemonic('s');
        c.add(suma);
        suma.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                double a,b,r;
                a=Double.parseDouble(t1.getText());
                b=Double.parseDouble(t2.getText());
                r=a+b;
                t3.setText(String.valueOf(r));
               
            }
           
        });
              
    }
}

0 comentarios:

Publicar un comentario