NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CALCULADORA2 extends JApplet implements ActionListener
{
JTextField t1,t2,t3;
JButton suma,resta,multi,divi;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
t1=new JTextField(30);
t2=new JTextField(30);
t3=new JTextField(30);
suma=new JButton("SUMAR");
resta=new JButton("RESTA");
multi=new JButton("MULTIPLICAR");
divi=new JButton("DIVIDIR");
suma.addActionListener(this);
resta.addActionListener(this);
multi.addActionListener(this);
divi.addActionListener(this);
c.add(t1);
c.add(t2);
c.add(t3);
c.add(suma);
c.add(resta);
c.add(multi);
c.add(divi);
}//metodo init
public void actionPerformed(ActionEvent e)
{
double a,b,s,r,m,d;
if(e.getSource()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
s=a+b;
t3.setText(String.valueOf(s));
}
if(e.getSource()==resta)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a-b;
t3.setText(String.valueOf(r));
}
if(e.getSource()==multi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
m=a*b;
t3.setText(String.valueOf(m));
}
if(e.getSource()==divi)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
d=a/b;
t3.setText(String.valueOf(d));
}
}
}
EL VIDEO ESTA EN http://www.youtube.com/user/rvnrodrigo
Suscribirse a:
Enviar comentarios (Atom)
0 comentarios:
Publicar un comentario