Calculadora En Java
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
importjava.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
importjavax.swing.JTextField;
import javax.swing.SwingConstants;
class Calculadora extends JFrame implements ActionListener, KeyListener{
private JTextField t= null;
private float oper1=0;
private floatoper2=0;
private double oper3=0;
private String command = null;
private boolean sw=true;
public Calculadora(){
this.setTitle("CALCULADORA.");
this.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent ev)
{
System.exit(0);
}
}
);
this.getContentPane().setLayout(new BorderLayout());
t= new JTextField(0);
t.setBackground(Color.green);t.setHorizontalAlignment(SwingConstants.CENTER);
t.addKeyListener(this);
JPanel aux = new JPanel();
aux.setLayout(new GridLayout(5,4));
JButton b = null;
b=new JButton("1");
b.addActionListener(this);
aux.add(b);b=new JButton("2");
b.addActionListener(this);
aux.add(b);
b=new JButton("3");
b.addActionListener(this);
aux.add(b);
b=new JButton("+");
b.addActionListener(this);
aux.add(b);
b=newJButton("4");
b.addActionListener(this);
aux.add(b);
b=new JButton("5");
b.addActionListener(this);
aux.add(b);
b=new JButton("6");
b.addActionListener(this);
aux.add(b);
b=new JButton("-");b.addActionListener(this);
aux.add(b);
b=new JButton("7");
b.addActionListener(this);
aux.add(b);
b=new JButton("8");
b.addActionListener(this);
aux.add(b);
b=new JButton("9");b.addActionListener(this);
aux.add(b);
b=new JButton("=");
b.addActionListener(this);
aux.add(b);
b=new JButton("%");
b.addActionListener(this);
aux.add(b);
b=new JButton("0");
b.addActionListener(this);...
Regístrate para leer el documento completo.