Forums:
hola a todos... soy kty.. y necesito urgentisiiima ayud... necesito hacer una calculadora censilla en java... con codigo simple... ya hise el diseño pero no se como hacer el resto
esto es lo que llevo... les agradesco si me ayudan
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//
public class Calculadora extends Applet implements ActionListener
{
Button b1, b2, b3, b4, b5, b6, b7, b8, b9, b0, bp, bi, bm, bme, bmu, bd, bc, bce;
TextField t1;
Panel p1, p2,p3, p4, p5, p6;
public Calculadora()
{
setLayout(new BorderLayout());
t1 = new TextField(" ");
add(t1, BorderLayout.NORTH);
setLayout(new FlowLayout());
p1 = new Panel(new BorderLayout());
p2 = new Panel(new BorderLayout());
p3 = new Panel(new BorderLayout());
p4 = new Panel(new BorderLayout());
p5 = new Panel(new BorderLayout());
p6 = new Panel(new BorderLayout());
b1 = new Button(" 1 ");
b2 = new Button(" 2 ");
b3 = new Button(" 3 ");
b4 = new Button(" 4 ");
b5 = new Button(" 5 ");
b6 = new Button(" 6 ");
b7 = new Button(" 7 ");
b8 = new Button(" 8 ");
b9 = new Button(" 9 ");
b0 = new Button(" 0 ");
bp = new Button(" . ");
bi = new Button(" = ");
bm = new Button(" + ");
bme = new Button(" - ");
bmu = new Button(" * ");
bd = new Button(" / ");
bc = new Button(" C ");
bce = new Button("CE");
//p1.add(t1);
p1.add(b1, BorderLayout.NORTH);
p1.add(b4, BorderLayout.CENTER);
p1.add(b7, BorderLayout.SOUTH);
p2.add(b2, BorderLayout.NORTH);
p2.add(b5, BorderLayout.CENTER);
p2.add(b8, BorderLayout.SOUTH);
p3.add(b3, BorderLayout.NORTH);
p3.add(b6, BorderLayout.CENTER);
p3.add(b9, BorderLayout.SOUTH);
p4.add(b0, BorderLayout.NORTH);
p4.add(bm, BorderLayout.CENTER);
p4.add(bce, BorderLayout.SOUTH);
p5.add(bp, BorderLayout.NORTH);
p5.add(bme, BorderLayout.CENTER);
p5.add(bc, BorderLayout.SOUTH);
p6.add(bd, BorderLayout.NORTH);
p6.add(bmu, BorderLayout.CENTER);
p6.add(bi, BorderLayout.SOUTH);
add(p1);
add(p2);
add(p3);
add(p4);
add(p5);
add(p6);
b1.addActionListener(this);
//b2.addActionListener(this);
//b3.addActionListener(this);
//b4.addActionListener(this);
//b5.addActionListener(this);
//b6.addActionListener(this);
//b7.addActionListener(this);
//b8.addActionListener(this);
//b9.addActionListener(this);
//b0.addActionListener(this);
//bp.addActionListener(this);
//bi.addActionListener(this);
//bm.addActionListener(this);
//bme.addActionListener(this);
//bmu.addActionListener(this);
//bd.addActionListener(this);
//bc.addActionListener(this);
//bce.addActionListener(this);
}
public void actionPerformed(ActionEvent calcu)
{
if (calcu.getSource() == b1)
{
t1.setText(b1.getSelectedItem());
}
}
}
Viva el plagio jaja .. pero
Viva el plagio jaja .. pero bueno sería recomendable que no solo te limites a copiar el código que te voy a dar sino también a entenderlo .. mira esta página http://foros.hackerss.com/lofiversion/index.php/t67.html
Saludos
DarHAc
censilla o sencilla !!!
censilla o sencilla !!!