PROMEDIO DE CALIFICACIONES CON JTEXTFIELD

LOS VIDEOS ESTAN EN http://www.youtube.com/user/rvnrodrigo
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class promedio1 extends JApplet implements ActionListener
{
    JTextField t1,t2,t3,t4;
    JButton b1,b2;
    public void init()
    {
    Container c=getContentPane();
    c.setLayout(new FlowLayout());
    t1=new JTextField(10);
    t2=new JTextField(10);
    t3=new JTextField(15);
    t4=new JTextField(15);
    b1=new JButton("PROMEDIAR");
    b2=new JButton("LIMPIAR");
    c.add(t1);
    c.add(t2);
    c.add(t3);
    c.add(t4);
    c.add(b1);
    c.add(b2);
    b1.addActionListener(this);
    b2.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {
        double a,b,r;
    if(e.getSource()==b1)
    {
        a=Double.parseDouble(t1.getText());
        b=Double.parseDouble(t2.getText());
        r=(a+b)/2;
        if(r<0 || r>10)
        {
            t4.setText("ERROR CAL NO VALIDA");
        }
 else
        {
        if(r>=0 && r<=5)
        {
            t3.setText(String.valueOf(r));
            t4.setText("REPROBADO");
        }
        if(r>=6 && r<=10)
        {
            t3.setText(String.valueOf(r));
            t4.setText("APROBADO");
        }
    }//else
    }//boton
    if(e.getSource()==b2)
    {
        t1.setText(" ");
        t2.setText(" ");
        t3.setText(" ");
        t4.setText(" ");
    }
    }//ACTION
}//CLASE

0 comentarios:

Publicar un comentario