NUEVO EJEMPLO
import javax.swing.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
public class SUMA_CHE extends JApplet implements ItemListener
{
JCheckBox suma,resta,lim;
JTextField t1,t2,t3;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
suma=new JCheckBox("SUMAR");
resta=new JCheckBox("RESTAR");
lim=new JCheckBox("LIMPIAR");
t1=new JTextField(30);
t2=new JTextField(30);
t3=new JTextField(30);
c.add(suma);
c.add(resta);
c.add(lim);
c.add(t1);
c.add(t2);
c.add(t3);
suma.addItemListener(this);
resta.addItemListener(this);
lim.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
{
double a,b,r;
if(e.getItemSelectable()==suma)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a+b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==resta)
{
a=Double.parseDouble(t1.getText());
b=Double.parseDouble(t2.getText());
r=a-b;
t3.setText(String.valueOf(r));
}
if(e.getItemSelectable()==lim)
{
t1.setText("");
t2.setText("");
t3.setText("");
}
}
}
Suscribirse a:
Enviar comentarios (Atom)
0 comentarios:
Publicar un comentario