0% found this document useful (0 votes)
30 views16 pages

Interfaz Calculadora

Uploaded by

Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views16 pages

Interfaz Calculadora

Uploaded by

Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 16

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;

/**
*
* @author Windows 10
*/
public class NewJFrameCalculadora extends javax.swing.JFrame {

/**
* Creates new form NewJFrameCalculadora
*/
private boolean punto=true;
String valor1, valor2, signo, contenido;
double resultado;
public NewJFrameCalculadora() {
initComponents();
}

/**
* 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() {

Pantalla = new javax.swing.JTextField();


btnmasomenos = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
btnln = new javax.swing.JButton();
btnasin = new javax.swing.JButton();
btnacos = new javax.swing.JButton();
btnatan = new javax.swing.JButton();
btnsqrt = new javax.swing.JButton();
btnsin = new javax.swing.JButton();
btncos = new javax.swing.JButton();
btntan = new javax.swing.JButton();
btn3sqrt = new javax.swing.JButton();
btnporcentaje = new javax.swing.JButton();
btndivision = new javax.swing.JButton();
btnmultiplicacion = new javax.swing.JButton();
btn7 = new javax.swing.JButton();
btn8 = new javax.swing.JButton();
btn9 = new javax.swing.JButton();
btnresta = new javax.swing.JButton();
btn2n = new javax.swing.JButton();
btn4 = new javax.swing.JButton();
btn5 = new javax.swing.JButton();
btn6 = new javax.swing.JButton();
btnsuma = new javax.swing.JButton();
pi = new javax.swing.JButton();
btn1 = new javax.swing.JButton();
btn2 = new javax.swing.JButton();
btn3 = new javax.swing.JButton();
btnborrar = new javax.swing.JButton();
btn0 = new javax.swing.JButton();
btnpunto = new javax.swing.JButton();
btnigual = new javax.swing.JButton();
btnsinh = new javax.swing.JButton();
btncosh = new javax.swing.JButton();
btntanh = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

Pantalla.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
PantallaActionPerformed(evt);
}
});

btnmasomenos.setText("+/-");
btnmasomenos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnmasomenosActionPerformed(evt);
}
});

jButton2.setText("e");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("x^n");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

btnln.setText("ln");
btnln.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnlnActionPerformed(evt);
}
});

btnasin.setText("sin-1");
btnasin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnasinActionPerformed(evt);
}
});

btnacos.setText("cos-1");

btnatan.setText("tan-1");

btnsqrt.setText("v");
btnsqrt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsqrtActionPerformed(evt);
}
});

btnsin.setText("sin");
btnsin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsinActionPerformed(evt);
}
});

btncos.setText("cos");
btncos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btncosActionPerformed(evt);
}
});

btntan.setText("tan");
btntan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btntanActionPerformed(evt);
}
});

btn3sqrt.setText("3v");
btn3sqrt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn3sqrtActionPerformed(evt);
}
});

btnporcentaje.setText("%");
btnporcentaje.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnporcentajeActionPerformed(evt);
}
});

btndivision.setText("/");
btndivision.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btndivisionActionPerformed(evt);
}
});

btnmultiplicacion.setText("*");
btnmultiplicacion.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnmultiplicacionActionPerformed(evt);
}
});

btn7.setText("7");
btn7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn7ActionPerformed(evt);
}
});

btn8.setText("8");
btn8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn8ActionPerformed(evt);
}
});

btn9.setText("9");
btn9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn9ActionPerformed(evt);
}
});

btnresta.setText("-");
btnresta.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnrestaActionPerformed(evt);
}
});

btn2n.setText("2^n");
btn2n.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn2nActionPerformed(evt);
}
});

btn4.setText("4");
btn4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn4ActionPerformed(evt);
}
});

btn5.setText("5");
btn5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn5ActionPerformed(evt);
}
});

btn6.setText("6");
btn6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn6ActionPerformed(evt);
}
});

btnsuma.setText("+");
btnsuma.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsumaActionPerformed(evt);
}
});
pi.setText("pi (n)");
pi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
piActionPerformed(evt);
}
});

btn1.setText("1");
btn1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn1ActionPerformed(evt);
}
});

btn2.setText("2");
btn2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn2ActionPerformed(evt);
}
});

btn3.setText("3");
btn3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn3ActionPerformed(evt);
}
});

btnborrar.setText("C");
btnborrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnborrarActionPerformed(evt);
}
});

btn0.setText("0");
btn0.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn0ActionPerformed(evt);
}
});

btnpunto.setText(".");
btnpunto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnpuntoActionPerformed(evt);
}
});

btnigual.setText("=");
btnigual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnigualActionPerformed(evt);
}
});

btnsinh.setText("sinh");

btncosh.setText("cosh");
btntanh.setText("tanh");

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Pantalla)
.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnsin)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btncos)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btntan)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn3sqrt)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnln))
.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(jButton2,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(pi,
javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnborrar,
javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn2n,
javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnsqrt,
javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)

.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btn7,
javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn8)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn9)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnresta,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(btnmasomenos,
javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8,
Short.MAX_VALUE)
.addComponent(btnporcentaje)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btndivision)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnmultiplicacion))))

.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(10, 10, 10)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(btn0,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnpunto))

.addGroup(layout.createSequentialGroup()
.addComponent(btn1,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn2)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnigual))

.addGroup(layout.createSequentialGroup()
.addComponent(btn4,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn5)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn6)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnsuma))))))
.addGroup(layout.createSequentialGroup()
.addComponent(btnasin)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnacos)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnatan)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3,
javax.swing.GroupLayout.PREFERRED_SIZE, 65,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(btnsinh)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btncosh)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btntanh)))
.addGap(0, 9, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(Pantalla, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(11, 11, 11)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnsinh)
.addComponent(btncosh)
.addComponent(btntanh))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnasin)
.addComponent(btnacos)
.addComponent(btnatan)
.addComponent(jButton3))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnsin)
.addComponent(btncos)
.addComponent(btntan)
.addComponent(btn3sqrt)
.addComponent(btnln))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnporcentaje)
.addComponent(btndivision)
.addComponent(btnmultiplicacion)
.addComponent(jButton2)
.addComponent(btnmasomenos))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn7)
.addComponent(btn8)
.addComponent(btn9)
.addComponent(btnresta)
.addComponent(btnsqrt))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn4)
.addComponent(btn5)
.addComponent(btn6)
.addComponent(btnsuma)
.addComponent(btn2n))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn1)
.addComponent(btn2)
.addComponent(btn3)
.addComponent(pi))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn0)
.addComponent(btnpunto)
.addComponent(btnborrar)))
.addComponent(btnigual, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(16, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"6");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"0");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"1");

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

Pantalla.setText(Pantalla.getText()+"2");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"3");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"4");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"5");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"7");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"8");
}

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

// TODO add your handling code here:


Pantalla.setText(Pantalla.getText()+"9");
}

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

// TODO add your handling code here:


}

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

// TODO add your handling code here:


Pantalla.setText("");
}

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

// TODO add your handling code here:


contenido=Pantalla.getText();
if(contenido.length()<=0){
Pantalla.setText("0.");

}else{
if(Pantalla.getText().contains(".")){

}else{
Pantalla.setText(Pantalla.getText()+".");
punto=false;
}
}
}
private void btnmasomenosActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


contenido=Pantalla.getText();
if(contenido.length()>0){
resultado=(-1)*Double.parseDouble(contenido);
Pantalla.setText(String.valueOf(resultado));
}

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

// TODO add your handling code here:


if(!Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="+";
Pantalla.setText("");

}
}

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


// TODO add your handling code here:
if(!Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="-";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(!Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="*";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(!Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="/";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(!Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="x^n";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


contenido=Pantalla.getText();
double xx=1;
if(contenido.length()>0){
xx=(Double.parseDouble(contenido)*Math.PI/180);
resultado=Math.sin(xx);
Pantalla.setText(String.valueOf(resultado));
}
}

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

contenido=Pantalla.getText();
double xx=1;
if(contenido.length()>0){
xx=(Double.parseDouble(contenido)*Math.PI/180);
resultado=Math.cos(xx);
Pantalla.setText(String.valueOf(resultado));
}
}

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

// TODO add your handling code here:


contenido=Pantalla.getText();
double xx=1;
if(contenido.length()>0){
xx=(Double.parseDouble(contenido)*Math.PI/180);
resultado=Math.tan(xx);
Pantalla.setText(String.valueOf(resultado));
}
}
}

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

// TODO add your handling code here:


if(Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="3sqrt";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="sqrt";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="%";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="e";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(Pantalla.getText().equals("")||(!Pantalla.getText().equals(""))){
valor1=Pantalla.getText();
signo="pi";
Pantalla.setText("");
}

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

// TODO add your handling code here:


if(Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="2^n";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


if(Pantalla.getText().equals("")){
valor1=Pantalla.getText();
signo="ln";
Pantalla.setText("");
}
}

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

// TODO add your handling code here:


String resultadototal;
valor2=Pantalla.getText();
if(!valor2.equals("")||(valor2.equals(""))){
resultadototal=operaciones(valor1, valor2, signo);
Pantalla.setText(resultadototal);
}
}

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

// TODO add your handling code here:


}

public static String operaciones(String valor1, String valor2, String signo){


double resultado=0;
String respuesta;
if(signo.equals("+")){
resultado=Double.parseDouble(valor1)+Double.parseDouble(valor2);
}else
if(signo.equals("-")){
resultado=Double.parseDouble(valor1)-Double.parseDouble(valor2);
}else
if(signo.equals("*")){

resultado=Double.parseDouble(valor1)*Double.parseDouble(valor2);
}else
if(signo.equals("/")){
resultado=Double.parseDouble(valor1)/Double.parseDouble(valor2);
}else
if(signo.equals("x^n")){
resultado=Math.pow(Double.parseDouble(valor1),
Double.parseDouble(valor2));
}
respuesta=String.valueOf(resultado);
return respuesta;
}

/**
* @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(NewJFrameCalculadora.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(NewJFrameCalculadora.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(NewJFrameCalculadora.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(NewJFrameCalculadora.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrameCalculadora().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Pantalla;
private javax.swing.JButton btn0;
private javax.swing.JButton btn1;
private javax.swing.JButton btn2;
private javax.swing.JButton btn2n;
private javax.swing.JButton btn3;
private javax.swing.JButton btn3sqrt;
private javax.swing.JButton btn4;
private javax.swing.JButton btn5;
private javax.swing.JButton btn6;
private javax.swing.JButton btn7;
private javax.swing.JButton btn8;
private javax.swing.JButton btn9;
private javax.swing.JButton btnacos;
private javax.swing.JButton btnasin;
private javax.swing.JButton btnatan;
private javax.swing.JButton btnborrar;
private javax.swing.JButton btncos;
private javax.swing.JButton btncosh;
private javax.swing.JButton btndivision;
private javax.swing.JButton btnigual;
private javax.swing.JButton btnln;
private javax.swing.JButton btnmasomenos;
private javax.swing.JButton btnmultiplicacion;
private javax.swing.JButton btnporcentaje;
private javax.swing.JButton btnpunto;
private javax.swing.JButton btnresta;
private javax.swing.JButton btnsin;
private javax.swing.JButton btnsinh;
private javax.swing.JButton btnsqrt;
private javax.swing.JButton btnsuma;
private javax.swing.JButton btntan;
private javax.swing.JButton btntanh;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton pi;
// End of variables declaration
}

You might also like