NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
public class SUMA_VENTANA extends Applet implements ActionListener
{
public TextField t1,t2,tr;
public Button b1;
public void init()
{
t1=new TextField(20);
t2=new TextField(20);
tr=new TextField(20);
b1=new Button(" SUMAR ");
add(t1);
add(t2);
add(tr);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
double a,b;
a=Double.parseDouble(t1.getText());//SE CONVIERTEN A DOUBLE
b=Double.parseDouble(t2.getText());
tr.setText(String.valueOf(a+b));//SE PASA COMO TEXTO
}
}
}//clase principal
Suscribirse a:
Enviar comentarios (Atom)
0 comentarios:
Publicar un comentario