Calculadora sencilla en java

Solo disponible en BuenasTareas
  • Páginas : 2 (387 palabras )
  • Descarga(s) : 0
  • Publicado : 25 de enero de 2012
Leer documento completo
Vista previa del texto
//propgrama integrado en modulos

//1º modulo

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class calculadora extends JFrame
{
privatefinal Font BIGGER_FONT = new Font("monspaced", Font.PLAIN, 20);
private JTextField textfield;
private boolean number = true;
private String equalOp = "=";
private calculadora Op = newcalculadoraOp();

//---------------------------------------------------------------------------------------------

// PROGRAMA INTEGRADO EN MODULOS

// 2º MODULO

public calculadora ()
{textfield = new JTextField("0", 12);
textfield.setHorizontalAlignment(JTextField.RIGHT);
textfield.setFont(BIGGER_FONT);

ActionListener numberListener = new NumberListener();
String buttonOrder ="1234567890 ";
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 4, 4, 4,));
for (int i = 0; i < buttonOrder.length(); i++) {
String key =buttonOrder.substring(i, i+1);
if (key.equals (" ")) {
buttonPanel.add(new JLabel(""));
} else {
JButton button = new JButton(key);
button.addActionListener(numberListener);button.setFor(BIGGER_FONT);
buttonPanel.add(button);
}
}

//--------------------------------------------------------
//programa integrado en modulos

// 3°modulo
ActionListener operatorListener = new OperatorListener();
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 4, 4, 4));
String[] opOrder = {"+", "-", "*", "/", "=","C"};
for (int i = 0; i < opOrder.length; i++)
{
JButton button = new JButton(opOrder[i]);
button.addActionListener(operatorListener);
button.setFont(BIGGER_FONT);panel.add(button);
}
// 4° modulo
JPanel pan = new JPanel();
pan.setLayout(new BorderLayout(4, 4));
pan.add(textfield, BorderLayout.NORTH );
pan.add(buttonPanel ,...
tracking img