Calculadora en Java

Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1de 46

CENTRO REGIONAL UNIVERSITARIO DE COCLÉ

FACULTAD DE INFORMÁTICA, ELECTRÓNICA Y COMUNICACIÓN

ESCUELA: INGENIERÍA EN INFORMÁTICA

CARRERA: LIC. DE INGENIERÍA EN INFORMÁTICA

ASIGNATURA:

PROGRAMACIÓN III (INF 222)

PROYECTO #1: INTERFAZ GRÁFICA (GRÁFICA)

TEMA:

INTERFACES GRÁFICAS DE USUARIO EN JAVA Y GESTIÓN DE EVENTOS

PROFESORA:

LILIBETH COMPARÁZ

PERTENECE A:

HEIDY M. SÁNCHEZ R. 2-750-1806

2 AÑO – SEGUNDO SEMESTRE

MIÉRCOLES, 9 DE NOVIEMBRE DE 2022


ADJUNTO CÓDIGO FUENTE DE LA INTERFAZ GRÁFICA DE LA

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;

/**

* @author HEIDY SANCHEZ

*/

public class CALCUINTERFAZ extends javax.swing.JFrame {

ScriptEngineManager cal = new ScriptEngineManager();

ScriptEngine se = cal.getEngineByName("JavaScript");

/**

* Creates new form CALCUINTERFAZ


*/

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

* regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

cuentag = new javax.swing.JLabel();

cuentap = new javax.swing.JLabel();


jPanel2 = new javax.swing.JPanel();

btn_8 = new javax.swing.JButton();

btn_7 = new javax.swing.JButton();

borrar = new javax.swing.JButton();

btn_mas = new javax.swing.JButton();

btn_9 = new javax.swing.JButton();

btn_men = new javax.swing.JButton();

btn_borr = new javax.swing.JButton();

btn_3 = new javax.swing.JButton();

btn_el = new javax.swing.JButton();

btn_6 = new javax.swing.JButton();

btn_1 = new javax.swing.JButton();

btn_2 = new javax.swing.JButton();

btn_p = new javax.swing.JButton();

btn_0 = new javax.swing.JButton();

btn_5 = new javax.swing.JButton();

btn_4 = new javax.swing.JButton();

btn_div = new javax.swing.JButton();


btn_porce = new javax.swing.JButton();

btn_por = new javax.swing.JButton();

btn_igual = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 255, 255));

jPanel1.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1,

new java.awt.Color(204, 204, 0)));

jPanel1.setForeground(new java.awt.Color(204, 0, 0));

cuentag.setFont(new java.awt.Font("Stencil", 1, 36)); // NOI18N

cuentag.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);

cuentap.setFont(new java.awt.Font("Bookman Old Style", 1, 18)); // NOI18N

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)

.addGap(15, 15, 15))

.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()

.addGap(18, 18, 18)

.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)

.addGap(19, 19, 19))

);

jPanel2.setBackground(new java.awt.Color(0, 153, 153));

jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new

java.awt.Color(0, 0, 0)));

btn_8.setBackground(new java.awt.Color(204, 255, 153));


btn_8.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_8.setText("8");

btn_8.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_8ActionPerformed(evt);

});

btn_7.setBackground(new java.awt.Color(204, 255, 153));

btn_7.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_7.setText("7");

btn_7.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_7ActionPerformed(evt);

});

borrar.setBackground(new java.awt.Color(255, 204, 204));


borrar.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N

borrar.setText("C");

borrar.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

borrarActionPerformed(evt);

});

btn_mas.setBackground(new java.awt.Color(204, 255, 255));

btn_mas.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_mas.setText("+");

btn_mas.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_masActionPerformed(evt);

});

btn_9.setBackground(new java.awt.Color(204, 255, 153));


btn_9.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_9.setText("9");

btn_9.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_9ActionPerformed(evt);

});

btn_men.setBackground(new java.awt.Color(204, 255, 255));

btn_men.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_men.setText("-");

btn_men.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_menActionPerformed(evt);

});

btn_borr.setBackground(new java.awt.Color(255, 204, 204));


btn_borr.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N

btn_borr.setText("CE");

btn_borr.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_borrActionPerformed(evt);

});

btn_3.setBackground(new java.awt.Color(204, 255, 153));

btn_3.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N

btn_3.setText("3");

btn_3.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_3ActionPerformed(evt);

});

btn_el.setBackground(new java.awt.Color(204, 255, 255));


btn_el.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_el.setText("^");

btn_el.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_elActionPerformed(evt);

});

btn_6.setBackground(new java.awt.Color(204, 255, 153));

btn_6.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_6.setText("6");

btn_6.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_6ActionPerformed(evt);

});

btn_1.setBackground(new java.awt.Color(204, 255, 153));


btn_1.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_1.setText("1");

btn_1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_1ActionPerformed(evt);

});

btn_2.setBackground(new java.awt.Color(204, 255, 153));

btn_2.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_2.setText("2");

btn_2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_2ActionPerformed(evt);

});

btn_p.setBackground(new java.awt.Color(255, 204, 204));


btn_p.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_p.setText(".");

btn_p.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_pActionPerformed(evt);

});

btn_0.setBackground(new java.awt.Color(204, 255, 153));

btn_0.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_0.setText("0");

btn_0.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_0ActionPerformed(evt);

});

btn_5.setBackground(new java.awt.Color(204, 255, 153));


btn_5.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_5.setText("5");

btn_5.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_5ActionPerformed(evt);

});

btn_4.setBackground(new java.awt.Color(204, 255, 153));

btn_4.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_4.setText("4");

btn_4.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_4ActionPerformed(evt);

});

btn_div.setBackground(new java.awt.Color(204, 255, 255));


btn_div.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_div.setText("/");

btn_div.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_divActionPerformed(evt);

});

btn_porce.setBackground(new java.awt.Color(204, 255, 255));

btn_porce.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_porce.setText("%");

btn_porce.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_porceActionPerformed(evt);

});

btn_por.setBackground(new java.awt.Color(210, 255, 255));


btn_por.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_por.setText("*");

btn_por.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_porActionPerformed(evt);

});

btn_igual.setBackground(new java.awt.Color(255, 204, 204));

btn_igual.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N

btn_igual.setText("=");

btn_igual.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btn_igualActionPerformed(evt);

});

javax.swing.GroupLayout jPanel2Layout = new

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,

javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)

.addComponent(btn_igual,

javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))

.addGroup(jPanel2Layout.createSequentialGroup()

.addGap(34, 34, 34)

.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 layout = new

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>

private void btn_8ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("8");

}
private void btn_7ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("7");

private void borrarActionPerformed(java.awt.event.ActionEvent evt) {

cuentap.setText(" ");

cuentag.setText(" ");

private void btn_masActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("+");

private void btn_9ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("9");

}
private void btn_menActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("-");

private void btn_borrActionPerformed(java.awt.event.ActionEvent evt) {

private void btn_3ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("3");

private void btn_elActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("^");

private void btn_6ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("6");
}

private void btn_1ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("1");

private void btn_2ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("2");

private void btn_pActionPerformed(java.awt.event.ActionEvent evt) {

addnumero (".");

private void btn_0ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("0");

}
private void btn_5ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("5");

private void btn_4ActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("4");

private void btn_divActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("/");

private void btn_porceActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("%");

private void btn_porActionPerformed(java.awt.event.ActionEvent evt) {

addnumero ("*");
}

private void btn_igualActionPerformed(java.awt.event.ActionEvent evt) {

try {

String resultado = se.eval(cuentag.getText()).toString();

cuentap.setText(resultado);

} catch (ScriptException ex) {

Logger.getLogger(CALCUINTERFAZ.class.getName()).log(Level.SEVERE, null,

ex);

public void addnumero (String digito){

cuentag.setText(cuentag.getText()+digito);

/**

* @param args the command line arguments

*/
public static void main(String args[]) {

/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code

(optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default

look and feel.

* For details see

http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info :

javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

} catch (ClassNotFoundException ex) {


java.util.logging.Logger.getLogger(CALCUINTERFAZ.class.getName()).log(java.ut

il.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(CALCUINTERFAZ.class.getName()).log(java.ut

il.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(CALCUINTERFAZ.class.getName()).log(java.ut

il.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(CALCUINTERFAZ.class.getName()).log(java.ut

il.logging.Level.SEVERE, null, ex);

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {

new CALCUINTERFAZ().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton borrar;

private javax.swing.JButton btn_0;

private javax.swing.JButton btn_1;

private javax.swing.JButton btn_2;

private javax.swing.JButton btn_3;

private javax.swing.JButton btn_4;

private javax.swing.JButton btn_5;

private javax.swing.JButton btn_6;

private javax.swing.JButton btn_7;

private javax.swing.JButton btn_8;

private javax.swing.JButton btn_9;


private javax.swing.JButton btn_borr;

private javax.swing.JButton btn_div;

private javax.swing.JButton btn_el;

private javax.swing.JButton btn_igual;

private javax.swing.JButton btn_mas;

private javax.swing.JButton btn_men;

private javax.swing.JButton btn_p;

private javax.swing.JButton btn_por;

private javax.swing.JButton btn_porce;

private javax.swing.JLabel cuentag;

private javax.swing.JLabel cuentap;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

// End of variables declaration

}
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

También podría gustarte