Calculadora java

Solo disponible en BuenasTareas
  • Páginas : 3 (652 palabras )
  • Descarga(s) : 0
  • Publicado : 15 de junio de 2011
Leer documento completo
Vista previa del texto
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Stack;

importjavax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JTextField;

public class Calculadora extends JApplet implements ActionListener {

private static final long serialVersionUID =3221707769370092517L;
Container container;
JTextField datos;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b0;
JButton opSuma, opResta, opMult, opDiv;
JButton punto, calcular, limpiar;
Stack pila;
charoperacion;
boolean operacionTerminada=false;

public void init(){
container = this.getContentPane();
container.setLayout( new GridLayout(6,1) );

pila = new Stack();

Font fuente= new Font("Verdana", Font.BOLD, 18);

/* Formato del campo de entrada */
datos = new JTextField();
datos.setFont(fuente);
datos.setEditable(false);

limpiar = newJButton("Limpiar");

Container renglon2 = new Container();
renglon2.setLayout( new GridLayout(1,4) );

Container renglon3 = new Container();
renglon3.setLayout( new GridLayout(1,4) );Container renglon4 = new Container();
renglon4.setLayout( new GridLayout(1,4) );

Container renglon5 = new Container();
renglon5.setLayout( new GridLayout(1,4) );

renglon2.add(b1 = newJButton("1"));
renglon2.add(b2 = new JButton("2"));
renglon2.add(b3 = new JButton("3"));
renglon2.add(opSuma = new JButton("+"));
renglon3.add(b4 = new JButton("4"));
renglon3.add(b5 =new JButton("5"));
renglon3.add(b6 = new JButton("6"));
renglon3.add(opResta = new JButton("-"));
renglon4.add(b7 = new JButton("7"));
renglon4.add(b8 = new JButton("8"));renglon4.add(b9 = new JButton("9"));
renglon4.add(opMult = new JButton("*"));
renglon5.add(punto = new JButton("."));
renglon5.add(b0 = new JButton("0"));
renglon5.add(calcular = new JButton("="));...
tracking img