Calculadora sencilla en java
//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 ,...
Regístrate para leer el documento completo.