lunes, 3 de agosto de 2009

50




import java.awt.*;
import java.applet.*;
import java.awt.Event;

public class Sumadora extends java.applet. Applet
{
void c (GridBagConstraints h, int gx, int gy, int gw,
int gh, int wx, int wy)
{
h.gridx=gx;
h.gridy=gy;
h.gridwidth=gw;
h.gridheight=gh;
h.weightx=wy;
h.weighty=wy;
}

Button sum,res,mul,div,lim;
Label n1,n2,n3,n4,opc,l;
TextField t1,t2,t3,t4,t5,t6;
Integer num,num1,num2,e;
public void init()
{
resize(700,500);
setBackground(Color.gray);
GridBagLayout dis=new GridBagLayout();
GridBagConstraints cf=new GridBagConstraints();
setLayout(dis);
c(cf,0,0,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
n1=new Label("INGRESE EL PRIMER NÙMERO");
n1.setFont(new Font("Tahoma",Font.BOLD,15));
dis.setConstraints(n1,cf);
add(n1);
//opc
c(cf,0,1,4,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
n3=new Label("ELIJA UNA OPCIÓN");
n3.setFont(new Font("Tahoma",Font.BOLD,21));
dis.setConstraints(n3,cf);
add(n3);

//t1
c(cf,1,0,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
t1=new TextField(7);
dis.setConstraints(t1,cf);
add(t1);

//et2
c(cf,2,0,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
n2=new Label("INGRESE EL SEGUNDO NÙMERO");
n2.setFont(new Font("Tahoma",Font.BOLD,15));
dis.setConstraints(n2,cf);
add(n2);
//t2
c(cf,3,0,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
t2=new TextField(7);
dis.setConstraints(t2,cf);
add(t2);

//sum
c(cf,0,2,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
sum=new Button("SUMA");
dis.setConstraints(sum,cf);
add(sum);
//ts
c(cf,1,2,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
t3=new TextField(7);
dis.setConstraints(t3,cf);
add(t3);
//res
c(cf,2,2,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
res=new Button("RESTA");
dis.setConstraints(res,cf);
add(res);
//tres
c(cf,3,2,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
t4=new TextField(7);
dis.setConstraints(t4,cf);
add(t4);
//mul
c(cf,0,3,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
mul=new Button("MULTIPLICAR");
dis.setConstraints(mul,cf);
add(mul);
//tmul
c(cf,1,3,1,1,0,0);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
t5=new TextField(7);
dis.setConstraints(t5,cf);
add(t5);
//div
c(cf,2,3,1,1,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
div=new Button("DIVIDIR");
dis.setConstraints(div,cf);
add(div);

//tdiv
c(cf,3,3,1,1,0,0);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
t6=new TextField(7);
dis.setConstraints(t6,cf);
add(t6);
//clear
c(cf,0,5,0,4,25,25);
cf.fill=(GridBagConstraints.NONE);
cf.anchor=GridBagConstraints.NORTH;
lim=new Button("LIMPIAR");
dis.setConstraints(lim,cf);
add(lim);
}
public boolean action (Event e,Object arg)
{
if(e.target instanceof Button)
{
String label=(String)arg;
if(label.equals ("SUMA"))
{
num1=Integer.parseInt(t1.getText());
num2=Integer.parseInt(t2.getText());
num=num1+num2;
t3.setText(Double.toString (num));
}
else
{
if(label.equals("RESTA"))
{
num1=Integer.parseInt(t1.getText());
num2=Integer.parseInt(t2.getText());
num=num1-num2;
t4.setText(Double.toString(num));
}
else
{
if(label.equals("MULTIPLICAR"))
{

num1=Integer.parseInt(t1.getText());
num2=Integer.parseInt(t2.getText());
num=num1*num2;
t5.setText(Double.toString(num));
}
else
{

num1=Integer.parseInt(t1.getText());
num2=Integer.parseInt(t2.getText());
num=num1/num2;
t6.setText(Double.toString(num));
}
}

}


}
return true;
}

}

No hay comentarios:

Publicar un comentario