Calculadora en Java
Calculadora en Java
Calculadora en Java
ASIGNATURA:
TEMA:
PROFESORA:
LILIBETH COMPARÁZ
PERTENECE A:
CALCULADORA
package com.mycompany.calculadora;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
/**
*/
ScriptEngine se = cal.getEngineByName("JavaScript");
/**
public CALCUINTERFAZ() {
initComponents();
setLocationRelativeTo(null);
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
*/
@SuppressWarnings("unchecked")
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1,
cuentag.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
cuentap.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
cuentap.setText("43323654788787");
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(cuentag)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(cuentap, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cuentap,
javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35,
Short.MAX_VALUE)
.addComponent(cuentag)
);
jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new
java.awt.Color(0, 0, 0)));
btn_8.setText("8");
btn_8.addActionListener(new java.awt.event.ActionListener() {
btn_8ActionPerformed(evt);
});
btn_7.setText("7");
btn_7.addActionListener(new java.awt.event.ActionListener() {
btn_7ActionPerformed(evt);
});
borrar.setText("C");
borrar.addActionListener(new java.awt.event.ActionListener() {
borrarActionPerformed(evt);
});
btn_mas.setText("+");
btn_mas.addActionListener(new java.awt.event.ActionListener() {
btn_masActionPerformed(evt);
});
btn_9.setText("9");
btn_9.addActionListener(new java.awt.event.ActionListener() {
btn_9ActionPerformed(evt);
});
btn_men.setText("-");
btn_men.addActionListener(new java.awt.event.ActionListener() {
btn_menActionPerformed(evt);
});
btn_borr.setText("CE");
btn_borr.addActionListener(new java.awt.event.ActionListener() {
btn_borrActionPerformed(evt);
});
btn_3.setText("3");
btn_3.addActionListener(new java.awt.event.ActionListener() {
btn_3ActionPerformed(evt);
});
btn_el.setText("^");
btn_el.addActionListener(new java.awt.event.ActionListener() {
btn_elActionPerformed(evt);
});
btn_6.setText("6");
btn_6.addActionListener(new java.awt.event.ActionListener() {
btn_6ActionPerformed(evt);
});
btn_1.setText("1");
btn_1.addActionListener(new java.awt.event.ActionListener() {
btn_1ActionPerformed(evt);
});
btn_2.setText("2");
btn_2.addActionListener(new java.awt.event.ActionListener() {
btn_2ActionPerformed(evt);
});
btn_p.setText(".");
btn_p.addActionListener(new java.awt.event.ActionListener() {
btn_pActionPerformed(evt);
});
btn_0.setText("0");
btn_0.addActionListener(new java.awt.event.ActionListener() {
btn_0ActionPerformed(evt);
});
btn_5.setText("5");
btn_5.addActionListener(new java.awt.event.ActionListener() {
btn_5ActionPerformed(evt);
});
btn_4.setText("4");
btn_4.addActionListener(new java.awt.event.ActionListener() {
btn_4ActionPerformed(evt);
});
btn_div.setText("/");
btn_div.addActionListener(new java.awt.event.ActionListener() {
btn_divActionPerformed(evt);
});
btn_porce.setText("%");
btn_porce.addActionListener(new java.awt.event.ActionListener() {
btn_porceActionPerformed(evt);
});
btn_por.setText("*");
btn_por.addActionListener(new java.awt.event.ActionListener() {
btn_porActionPerformed(evt);
});
btn_igual.setText("=");
btn_igual.addActionListener(new java.awt.event.ActionListener() {
btn_igualActionPerformed(evt);
});
javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(btn_7,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_8,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_9,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_mas,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(borrar,
javax.swing.GroupLayout.PREFERRED_SIZE, 63,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING)
.addComponent(btn_4,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_1,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_p,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(btn_5,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_6,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_men,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(btn_0,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_el,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_div,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(btn_2,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_3,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_por,
javax.swing.GroupLayout.PREFERRED_SIZE, 51,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING)
.addComponent(btn_porce,
javax.swing.GroupLayout.Alignment.TRAILING,
.addComponent(btn_igual,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(btn_borr,
javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE)))))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(9, 9, 9)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.BASELINE)
.addComponent(btn_8,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_9,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_mas,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(borrar,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_7,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.BASELINE)
.addComponent(btn_borr,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_5,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_4,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_6,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_men,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.BASELINE)
.addComponent(btn_3,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_porce,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.BASELINE)
.addComponent(btn_2,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_1,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(btn_por,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.BASELINE)
.addComponent(btn_p,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_0,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_el,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_div,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_igual,
javax.swing.GroupLayout.PREFERRED_SIZE, 38,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(20, Short.MAX_VALUE))
);
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
addnumero ("8");
}
private void btn_7ActionPerformed(java.awt.event.ActionEvent evt) {
addnumero ("7");
cuentap.setText(" ");
cuentag.setText(" ");
addnumero ("+");
addnumero ("9");
}
private void btn_menActionPerformed(java.awt.event.ActionEvent evt) {
addnumero ("-");
addnumero ("3");
addnumero ("^");
addnumero ("6");
}
addnumero ("1");
addnumero ("2");
addnumero (".");
addnumero ("0");
}
private void btn_5ActionPerformed(java.awt.event.ActionEvent evt) {
addnumero ("5");
addnumero ("4");
addnumero ("/");
addnumero ("%");
addnumero ("*");
}
try {
cuentap.setText(resultado);
Logger.getLogger(CALCUINTERFAZ.class.getName()).log(Level.SEVERE, null,
ex);
cuentag.setText(cuentag.getText()+digito);
/**
*/
public static void main(String args[]) {
(optional) ">
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
java.util.logging.Logger.getLogger(CALCUINTERFAZ.class.getName()).log(java.ut
java.util.logging.Logger.getLogger(CALCUINTERFAZ.class.getName()).log(java.ut
java.util.logging.Logger.getLogger(CALCUINTERFAZ.class.getName()).log(java.ut
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CALCUINTERFAZ().setVisible(true);
});
}
SUMA DE CUATRO CIFRAS
8,282
RESTA DE CUATRO CIFRAS
4,263
SUMA CON PUNTO DECIMAL (REAL)
11.77
RESTA CON PUNTO DECIMAL (REAL)
14.06
MULTIPLICACIÓN DE NÚMEROS ENTEROS
3,648
MULTIPLICACIÓN DE NÚMEROS CON PUNTO DECIMAL
18.075
DIVISIÓN CON NÚMEROS ENTEROS
153.3333333
DIVISIÓN DE NÚMEROS CON PUNTO DECIMAL
16.05