culadora cientifica en java

73
ALCULADORA CIENTIFICA EN NETBEANS Filed under: PORTAFOLIO ELECTRÓNICO Deja un comentario junio 6, 2011 CLASS_CAL: package calcu; /** * * @author Luis Heriberto Soto Mendoza */ public class Class_cal { private double n1; private double seno; private double n2; public void Setn1(double n1) { this.n1=n1; } public double Getn1() { return this.n1; } public void Setn2(double n2) { this.n2=n2; } public double Getn2() { return this.n2; } public Class_cal() { this.n1=0; this.n2=0; }

Transcript of culadora cientifica en java

Page 1: culadora cientifica en java

ALCULADORA CIENTIFICA EN NETBEANSFiled under: PORTAFOLIO ELECTRÓNICO — Deja un comentario

junio 6, 2011

CLASS_CAL:

package calcu;

/**

 *

 * @author Luis Heriberto Soto Mendoza

 */

public class Class_cal {

 private double n1;

 private double seno;

    private double n2;

    public void Setn1(double n1)

    {

        this.n1=n1;

    }

    public double Getn1()

    {

        return this.n1;

    }

     public void Setn2(double n2)

    {

        this.n2=n2;

    }

    public double Getn2()

    {

        return this.n2;

    }

    public Class_cal()

    {

        this.n1=0;

        this.n2=0;

    }

    public double Sumar()

    {

Page 2: culadora cientifica en java

        return this.n1+this.n2;

    }

    public double Restar()

    {

        return this.n1-this.n2;

    }

    public double Multiplicar()

    {

        return this.n1*this.n2;

    }

    public double Dividir()

    {

     

        return this.n1/this.n2;

    }

public double seno()

    {  

        n1= Math.sin(n1);

        return this.n1 ;

               

    }

public double coseno()

    {

        n1= Math.cos(n1);

        return this.n1 ;

    }

public double tangente()

    {

        n1= Math.tan(n1);

        return this.n1 ;

}

public double cotangente()

    {

        n1= 1/Math.tan(n1);

        return this.n1 ;

}

Page 3: culadora cientifica en java

public double Raiz()

    {

        n1= Math.sqrt(n1);

        return this.n1 ;

}

public double factorial()

    {

         double i,fact,cont;

        cont=1;

        fact=n1;

        for(i=1;i<=fact;i++){

           cont=cont*i;

        }

        n1=cont;

        return this.n1 ;

}

public double cuadrado()

    {

         double i,cuadrado,cont;

        cont=0;

        cuadrado=n1;

        for(i=1;i<=2;i++){

           cont=cuadrado*cuadrado;

        }

        n1=cont;

        return this.n1 ;

}

public double cubo()

    {

         double i,cubo,cont;

        cont=0;

        cubo=n1;

        for(i=1;i<=2;i++){

           cont=cubo*cubo*cubo;

        }

        n1=cont;

Page 4: culadora cientifica en java

        return this.n1 ;

}

}

 

MAIN:

package calcu;

/**

 *

 * @author Luis Heriberto Soto Mendoza

 */

public class Main {

 

    public static void main(String[] args) {

       form_cal obj_frm_cal = new form_cal();

        obj_frm_cal.setVisible(true);

    }

}

 

FORMULARIO:

 

package calcu;

/**

 *

 * @author Luis Heriberto Soto Mendoza

 */

public class form_cal extends javax.swing.JFrame {

 

    public form_cal() {

        initComponents();

    }

    @SuppressWarnings(“unchecked”)

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

    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();

        jButton16 = new javax.swing.JButton();

        jButton15 = new javax.swing.JButton();

Page 5: culadora cientifica en java

        jButton17 = new javax.swing.JButton();

        jButton13 = new javax.swing.JButton();

        jButton14 = new javax.swing.JButton();

        jButton11 = new javax.swing.JButton();

        jButton12 = new javax.swing.JButton();

        jButton9 = new javax.swing.JButton();

        jButton10 = new javax.swing.JButton();

        jButton19 = new javax.swing.JButton();

        jButton18 = new javax.swing.JButton();

        jButton20 = new javax.swing.JButton();

        jButton21 = new javax.swing.JButton();

        jButton22 = new javax.swing.JButton();

        jButton23 = new javax.swing.JButton();

        jButton24 = new javax.swing.JButton();

        jButton25 = new javax.swing.JButton();

        jButton26 = new javax.swing.JButton();

        jButton27 = new javax.swing.JButton();

        jButton2 = new javax.swing.JButton();

        jButton1 = new javax.swing.JButton();

        jButton8 = new javax.swing.JButton();

        jButton6 = new javax.swing.JButton();

        jButton5 = new javax.swing.JButton();

        jButton4 = new javax.swing.JButton();

        jButton3 = new javax.swing.JButton();

        jButton7 = new javax.swing.JButton();

        txt = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

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

        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

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

        jButton16.setBackground(new java.awt.Color(255, 51, 0));

        jButton16.setText(“sen”);

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

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

                jButton16ActionPerformed(evt);

Page 6: culadora cientifica en java

            }

        });

        jButton15.setText(“9″);

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

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

                jButton15ActionPerformed(evt);

            }

        });

        jButton17.setText(“0″);

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

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

                jButton17ActionPerformed(evt);

            }

        });

        jButton13.setText(“7″);

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

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

                jButton13ActionPerformed(evt);

            }

        });

        jButton14.setText(“8″);

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

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

                jButton14ActionPerformed(evt);

            }

        });

        jButton11.setText(“=”);

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

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

                jButton11ActionPerformed(evt);

            }

        });

        jButton12.setText(“AC”);

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

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

                jButton12ActionPerformed(evt);

Page 7: culadora cientifica en java

            }

        });

        jButton9.setBackground(new java.awt.Color(51, 255, 51));

        jButton9.setText(“x”);

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

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

                jButton9ActionPerformed(evt);

            }

        });

        jButton10.setBackground(new java.awt.Color(51, 255, 51));

        jButton10.setText(“/”);

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

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

                jButton10ActionPerformed(evt);

            }

        });

        jButton19.setBackground(new java.awt.Color(255, 51, 0));

        jButton19.setText(“tan”);

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

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

                jButton19ActionPerformed(evt);

            }

        });

        jButton18.setBackground(new java.awt.Color(255, 51, 0));

        jButton18.setText(“cos”);

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

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

                jButton18ActionPerformed(evt);

            }

        });

        jButton20.setBackground(new java.awt.Color(255, 51, 0));

        jButton20.setText(“fact”);

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

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

                jButton20ActionPerformed(evt);

Page 8: culadora cientifica en java

            }

        });

        jButton21.setText(“PI”);

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

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

                jButton21ActionPerformed(evt);

            }

        });

        jButton22.setBackground(new java.awt.Color(255, 51, 0));

        jButton22.setText(“Raiz”);

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

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

                jButton22ActionPerformed(evt);

            }

        });

        jButton23.setText(“.”);

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

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

                jButton23ActionPerformed(evt);

            }

        });

        jButton24.setText(“atras”);

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

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

                jButton24ActionPerformed(evt);

            }

        });

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

        jButton25.setText(“X^2″);

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

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

                jButton25ActionPerformed(evt);

            }

        });

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

        jButton26.setText(“X^3″);

Page 9: culadora cientifica en java

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

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

                jButton26ActionPerformed(evt);

            }

        });

        jButton27.setBackground(new java.awt.Color(255, 51, 0));

        jButton27.setText(“cot”);

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

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

                jButton27ActionPerformed(evt);

            }

        });

        jButton2.setText(“2″);

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

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

                jButton2ActionPerformed(evt);

            }

        });

        jButton1.setText(“1″);

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

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

                jButton1ActionPerformed(evt);

            }

        });

        jButton8.setBackground(new java.awt.Color(51, 255, 51));

        jButton8.setText(“-“);

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

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

                jButton8ActionPerformed(evt);

            }

        });

        jButton6.setText(“6″);

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

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

                jButton6ActionPerformed(evt);

Page 10: culadora cientifica en java

            }

        });

        jButton5.setText(“5″);

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

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

                jButton5ActionPerformed(evt);

            }

        });

        jButton4.setText(“4″);

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

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

                jButton4ActionPerformed(evt);

            }

        });

        jButton3.setText(“3″);

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

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

                jButton3ActionPerformed(evt);

            }

        });

        jButton7.setBackground(new java.awt.Color(51, 255, 51));

        jButton7.setFont(new java.awt.Font(“Tahoma”, 1, 11)); // NOI18N

        jButton7.setText(“+”);

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

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

                jButton7ActionPerformed(evt);

            }

        });

        jButton7.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyPressed(java.awt.event.KeyEvent evt) {

                jButton7KeyPressed(evt);

            }

        });

        txt.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

        jPanel1.setLayout(jPanel1Layout);

Page 11: culadora cientifica en java

        jPanel1Layout.setHorizontalGroup(

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addContainerGap()

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

jPanel1Layout.createSequentialGroup()

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addComponent(jButton16)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton18)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton19)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton27, javax.swing.GroupLayout.DEFAULT_SIZE,

51, Short.MAX_VALUE))

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                                    .addComponent(jButton23, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE))

                                .addPreferredGap

Page 12: culadora cientifica en java

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                                    .addGroup(jPanel1Layout.createSequentialGroup()

                                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                                            .addComponent(jButton14

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

                                            .addComponent(jButton11

,javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,

68, Short.MAX_VALUE)

                                            .addComponent(jButton5, 0, 0, Short.MAX_VALUE))

                                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)

                                            .addComponent(jButton6

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

                                            .addComponent(jButton15

, javax.swing.GroupLayout.Alignment.LEADING,javax.swing.GroupLayout.DEFAULT_SIZE, 67,

Short.MAX_VALUE)

                                            .addComponent(jButton21

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

                                    .addGroup(jPanel1Layout.createSequentialGroup()

                                        .addComponent(jButton2

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

                                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                        .addComponent(jButton3

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

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

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                            .addComponent(jButton20, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Short.MAX_VALUE)

                            .addComponent(jButton22, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Page 13: culadora cientifica en java

Short.MAX_VALUE)

                            .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Short.MAX_VALUE)

                            .addComponent(jButton8

, javax.swing.GroupLayout.Alignment.TRAILING,javax.swing.GroupLayout.DEFAULT_SIZE,

59, Short.MAX_VALUE)

                            .addComponent(jButton9, javax.swing.GroupLayout.Alignment.TRAILING,

0, 0, Short.MAX_VALUE)

                            .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Short.MAX_VALUE)))

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addComponent(jButton25, javax.swing.GroupLayout.DEFAULT_SIZE,

55, Short.MAX_VALUE)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton26, javax.swing.GroupLayout.DEFAULT_SIZE,

55, Short.MAX_VALUE)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton24, javax.swing.GroupLayout.DEFAULT_SIZE,

67, Short.MAX_VALUE)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE,

68,javax.swing.GroupLayout.PREFERRED_SIZE))

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addGap(18, 18, 18)

                                .addComponent(txt, javax.swing.GroupLayout.PREFERRED_SIZE,

238,javax.swing.GroupLayout.PREFERRED_SIZE)))

                        .addGap(18, 18, 18)))

                .addContainerGap())

        );

        jPanel1Layout.setVerticalGroup(

Page 14: culadora cientifica en java

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(txt, javax.swing.GroupLayout.PREFERRED_SIZE,

29,javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addGap(17, 17, 17)

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton26)

                            .addComponent(jButton25)

                            .addComponent(jButton24)))

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

                        .addComponent(jButton12)))

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

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE,

23,javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jButton18)

                    .addComponent(jButton19)

                    .addComponent(jButton27)

                    .addComponent(jButton22))

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(jPanel1Layout.createSequentialGroup()

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

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton20)

                            .addComponent(jButton13)

                            .addComponent(jButton14)

Page 15: culadora cientifica en java

                            .addComponent(jButton15))

                        .addGap(35, 35, 35)

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton1)

                            .addComponent(jButton2)

                            .addComponent(jButton3))

                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED,javax.swing.GroupLayout.DEFAUL

T_SIZE, Short.MAX_VALUE)

                        .addComponent(jButton17)

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

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton23)

                            .addComponent(jButton21)

                            .addComponent(jButton11)))

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

jPanel1Layout.createSequentialGroup()

                        .addGap(35, 35, 35)

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton7)

                            .addComponent(jButton4)

                            .addComponent(jButton6)

                            .addComponent(jButton5))

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

                        .addComponent(jButton8)

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

                        .addComponent(jButton9)

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

                        .addComponent(jButton10)))

                .addContainerGap())

        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

Page 16: culadora cientifica en java

        layout.setHorizontalGroup(

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

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

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

                .addComponent(jPanel1

, javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, javax

.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );

        layout.setVerticalGroup(

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

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

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

                .addComponent(jPanel1

, javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, javax

.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );

        pack();

    }// </editor-fold>

public double acum;

public double valor;

public double no;

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

    if (no>0)

    {

      txt.setText(“”); 

       txt.setText(txt.getText()+ String.valueOf(1));

       no=0;

       }

    else{

        txt.setText(txt.getText()+ String.valueOf(1));

   

Page 17: culadora cientifica en java

    }

   

    }                                       

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

{                                        

    if (no>0)

    {

      txt.setText(“”);

       txt.setText(txt.getText()+ String.valueOf(2));

       no=0;

       }

    else{

        txt.setText(txt.getText()+ String.valueOf(2));

  

    }

   

    }                                       

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

{                                        

    if (no>0)

    {

      txt.setText(“”);

       txt.setText(txt.getText()+ String.valueOf(3));

       no=0;

       }

    else{

        txt.setText(txt.getText()+ String.valueOf(3));

   

    }

   

    }                                       

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

    if (no>0)

    {

      txt.setText(“”);

Page 18: culadora cientifica en java

      txt.setText(txt.getText()+ String.valueOf(4));

      no=0;

       }

    else{

        txt.setText(txt.getText()+ String.valueOf(4));

   

    }

   

    }                                       

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

     if (no>0)

    {

      txt.setText(“”);

      txt.setText(txt.getText()+ String.valueOf(5));

      no=0;

    }

    else

    {

       txt.setText(txt.getText()+ String.valueOf(5));

   

    }

    

    }                                       

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

    if (no>0)

    {

      txt.setText(“”);

      txt.setText(txt.getText()+ String.valueOf(6));

       no=0;

    }

    else

    {

      txt.setText(txt.getText()+ String.valueOf(6));

   

Page 19: culadora cientifica en java

    }

  

    }                                       

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

          Class_cal Obj_calc=new Class_cal();

  

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=1;

   

    }                                       

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

Page 20: culadora cientifica en java

   

if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }                                        

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

   

   

    }

         valor=0;

         no=1;

    }

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        txt.setText(“”);

        acum=0;

        valor=0;

    }                                        

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

        Class_cal Obj_calc=new Class_cal();

 

Page 21: culadora cientifica en java

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

 if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

  if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Dividir()+””);

    }

  else

        acum=Double.parseDouble (txt.getText());

        txt.setText(“”);

        valor=2;

    }                                       

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

        Class_cal Obj_calc=new Class_cal();

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

Page 22: culadora cientifica en java

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=3;

    }                                       

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

       Class_cal Obj_calc=new Class_cal();

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

Page 23: culadora cientifica en java

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=4;

    }                                        

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

    if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(7));

      no=0;

    }

    else

    {

     txt.setText(txt.getText()+ String.valueOf(7));

   

    }

    }                                        

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

    if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(8));

     no=0;

    }

    else

    {

     txt.setText(txt.getText()+ String.valueOf(8));

    

Page 24: culadora cientifica en java

    }

    }                                        

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

    if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(9));

     no=0;

    }

    else

    {

     txt.setText(txt.getText()+ String.valueOf(9));

    

    }

    }                                        

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

   if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(0));

     no=0;

    }

    else

    {

     txt.setText(txt.getText()+ String.valueOf(0));

    

    }

    }                                        

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.seno()+””);

    }                                        

Page 25: culadora cientifica en java

    private void jButton18ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

          Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.coseno()+””);

    }                                        

    private void jButton19ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

           Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.tangente()+””);

    }                                        

    private void jButton20ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

           Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.factorial()+””);

    }                                        

    private void jButton22ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

           Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.Raiz()+””);

    }                                        

    private void jButton23ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        String cadena;

        int punto;

        cadena = txt.getText();

        punto = cadena.indexOf(‘.’);

        if (punto==-1)

         {

          txt.setText(txt.getText()+(“.”));

         }

    }                                        

Page 26: culadora cientifica en java

    private void jButton24ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        String cadena = txt.getText();

        if(!txt.equals(“”))

        txt.setText(cadena.substring(0, cadena.length() – 1));

    }                                        

    private void jButton21ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        txt.setText(String.valueOf(“3.14″));

    }                                        

    private void jButton25ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.cuadrado()+””);

    }                                        

    private void jButton26ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.cubo()+””);

    }                                        

    private void jButton27ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

         Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.cotangente()+””);

    }                                        

    private void jButton7KeyPressed(java.awt.event.KeyEvent evt) {                                   

         Class_cal Obj_calc=new Class_cal();

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

Page 27: culadora cientifica en java

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=1;

   

    }                                  

    /**

    * @param args the command line arguments

    */

    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new form_cal().setVisible(true);

            }

        });

    }    // Variables declaration – do not modify    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton10;    private javax.swing.JButton jButton11;    private javax.swing.JButton jButton12;    private javax.swing.JButton jButton13;    private javax.swing.JButton jButton14;    private javax.swing.JButton jButton15;    private javax.swing.JButton jButton16;

Page 28: culadora cientifica en java

    private javax.swing.JButton jButton17;    private javax.swing.JButton jButton18;    private javax.swing.JButton jButton19;    private javax.swing.JButton jButton2;    private javax.swing.JButton jButton20;    private javax.swing.JButton jButton21;    private javax.swing.JButton jButton22;    private javax.swing.JButton jButton23;    private javax.swing.JButton jButton24;    private javax.swing.JButton jButton25;    private javax.swing.JButton jButton26;    private javax.swing.JButton jButton27;    private javax.swing.JButton jButton3;    private javax.swing.JButton jButton4;    private javax.swing.JButton jButton5;

    private javax.swing.JButton jButton6; ALCULADORA CIENTIFICA EN NETBEANSFiled under: PORTAFOLIO ELECTRÓNICO — Deja un comentario

junio 6, 2011

CLASS_CAL:

package calcu;

/**

 *

 * @author Luis Heriberto Soto Mendoza

 */

public class Class_cal {

 private double n1;

 private double seno;

    private double n2;

    public void Setn1(double n1)

    {

        this.n1=n1;

    }

    public double Getn1()

    {

        return this.n1;

    }

     public void Setn2(double n2)

    {

        this.n2=n2;

    }

Page 29: culadora cientifica en java

    public double Getn2()

    {

        return this.n2;

    }

    public Class_cal()

    {

        this.n1=0;

        this.n2=0;

    }

    public double Sumar()

    {

        return this.n1+this.n2;

    }

    public double Restar()

    {

        return this.n1-this.n2;

    }

    public double Multiplicar()

    {

        return this.n1*this.n2;

    }

    public double Dividir()

    {

     

        return this.n1/this.n2;

    }

public double seno()

    {  

        n1= Math.sin(n1);

        return this.n1 ;

               

    }

public double coseno()

    {

        n1= Math.cos(n1);

        return this.n1 ;

Page 30: culadora cientifica en java

    }

public double tangente()

    {

        n1= Math.tan(n1);

        return this.n1 ;

}

public double cotangente()

    {

        n1= 1/Math.tan(n1);

        return this.n1 ;

}

public double Raiz()

    {

        n1= Math.sqrt(n1);

        return this.n1 ;

}

public double factorial()

    {

         double i,fact,cont;

        cont=1;

        fact=n1;

        for(i=1;i<=fact;i++){

           cont=cont*i;

        }

        n1=cont;

        return this.n1 ;

}

public double cuadrado()

    {

         double i,cuadrado,cont;

        cont=0;

        cuadrado=n1;

        for(i=1;i<=2;i++){

           cont=cuadrado*cuadrado;

        }

        n1=cont;

Page 31: culadora cientifica en java

        return this.n1 ;

}

public double cubo()

    {

         double i,cubo,cont;

        cont=0;

        cubo=n1;

        for(i=1;i<=2;i++){

           cont=cubo*cubo*cubo;

        }

        n1=cont;

        return this.n1 ;

}

}

 

MAIN:

package calcu;

/**

 *

 * @author Luis Heriberto Soto Mendoza

 */

public class Main {

 

    public static void main(String[] args) {

       form_cal obj_frm_cal = new form_cal();

        obj_frm_cal.setVisible(true);

    }

}

 

FORMULARIO:

 

package calcu;

/**

 *

 * @author Luis Heriberto Soto Mendoza

Page 32: culadora cientifica en java

 */

public class form_cal extends javax.swing.JFrame {

 

    public form_cal() {

        initComponents();

    }

    @SuppressWarnings(“unchecked”)

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

    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();

        jButton16 = new javax.swing.JButton();

        jButton15 = new javax.swing.JButton();

        jButton17 = new javax.swing.JButton();

        jButton13 = new javax.swing.JButton();

        jButton14 = new javax.swing.JButton();

        jButton11 = new javax.swing.JButton();

        jButton12 = new javax.swing.JButton();

        jButton9 = new javax.swing.JButton();

        jButton10 = new javax.swing.JButton();

        jButton19 = new javax.swing.JButton();

        jButton18 = new javax.swing.JButton();

        jButton20 = new javax.swing.JButton();

        jButton21 = new javax.swing.JButton();

        jButton22 = new javax.swing.JButton();

        jButton23 = new javax.swing.JButton();

        jButton24 = new javax.swing.JButton();

        jButton25 = new javax.swing.JButton();

        jButton26 = new javax.swing.JButton();

        jButton27 = new javax.swing.JButton();

        jButton2 = new javax.swing.JButton();

        jButton1 = new javax.swing.JButton();

        jButton8 = new javax.swing.JButton();

        jButton6 = new javax.swing.JButton();

        jButton5 = new javax.swing.JButton();

        jButton4 = new javax.swing.JButton();

        jButton3 = new javax.swing.JButton();

Page 33: culadora cientifica en java

        jButton7 = new javax.swing.JButton();

        txt = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

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

        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

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

        jButton16.setBackground(new java.awt.Color(255, 51, 0));

        jButton16.setText(“sen”);

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

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

                jButton16ActionPerformed(evt);

            }

        });

        jButton15.setText(“9″);

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

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

                jButton15ActionPerformed(evt);

            }

        });

        jButton17.setText(“0″);

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

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

                jButton17ActionPerformed(evt);

            }

        });

        jButton13.setText(“7″);

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

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

                jButton13ActionPerformed(evt);

            }

        });

        jButton14.setText(“8″);

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

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

                jButton14ActionPerformed(evt);

Page 34: culadora cientifica en java

            }

        });

        jButton11.setText(“=”);

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

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

                jButton11ActionPerformed(evt);

            }

        });

        jButton12.setText(“AC”);

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

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

                jButton12ActionPerformed(evt);

            }

        });

        jButton9.setBackground(new java.awt.Color(51, 255, 51));

        jButton9.setText(“x”);

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

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

                jButton9ActionPerformed(evt);

            }

        });

        jButton10.setBackground(new java.awt.Color(51, 255, 51));

        jButton10.setText(“/”);

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

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

                jButton10ActionPerformed(evt);

            }

        });

        jButton19.setBackground(new java.awt.Color(255, 51, 0));

        jButton19.setText(“tan”);

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

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

                jButton19ActionPerformed(evt);

            }

        });

Page 35: culadora cientifica en java

        jButton18.setBackground(new java.awt.Color(255, 51, 0));

        jButton18.setText(“cos”);

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

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

                jButton18ActionPerformed(evt);

            }

        });

        jButton20.setBackground(new java.awt.Color(255, 51, 0));

        jButton20.setText(“fact”);

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

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

                jButton20ActionPerformed(evt);

            }

        });

        jButton21.setText(“PI”);

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

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

                jButton21ActionPerformed(evt);

            }

        });

        jButton22.setBackground(new java.awt.Color(255, 51, 0));

        jButton22.setText(“Raiz”);

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

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

                jButton22ActionPerformed(evt);

            }

        });

        jButton23.setText(“.”);

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

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

                jButton23ActionPerformed(evt);

            }

        });

        jButton24.setText(“atras”);

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

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

Page 36: culadora cientifica en java

                jButton24ActionPerformed(evt);

            }

        });

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

        jButton25.setText(“X^2″);

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

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

                jButton25ActionPerformed(evt);

            }

        });

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

        jButton26.setText(“X^3″);

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

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

                jButton26ActionPerformed(evt);

            }

        });

        jButton27.setBackground(new java.awt.Color(255, 51, 0));

        jButton27.setText(“cot”);

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

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

                jButton27ActionPerformed(evt);

            }

        });

        jButton2.setText(“2″);

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

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

                jButton2ActionPerformed(evt);

            }

        });

        jButton1.setText(“1″);

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

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

                jButton1ActionPerformed(evt);

            }

        });

Page 37: culadora cientifica en java

        jButton8.setBackground(new java.awt.Color(51, 255, 51));

        jButton8.setText(“-“);

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

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

                jButton8ActionPerformed(evt);

            }

        });

        jButton6.setText(“6″);

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

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

                jButton6ActionPerformed(evt);

            }

        });

        jButton5.setText(“5″);

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

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

                jButton5ActionPerformed(evt);

            }

        });

        jButton4.setText(“4″);

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

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

                jButton4ActionPerformed(evt);

            }

        });

        jButton3.setText(“3″);

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

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

                jButton3ActionPerformed(evt);

            }

        });

        jButton7.setBackground(new java.awt.Color(51, 255, 51));

        jButton7.setFont(new java.awt.Font(“Tahoma”, 1, 11)); // NOI18N

        jButton7.setText(“+”);

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

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

Page 38: culadora cientifica en java

                jButton7ActionPerformed(evt);

            }

        });

        jButton7.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyPressed(java.awt.event.KeyEvent evt) {

                jButton7KeyPressed(evt);

            }

        });

        txt.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

        jPanel1.setLayout(jPanel1Layout);

        jPanel1Layout.setHorizontalGroup(

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addContainerGap()

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

jPanel1Layout.createSequentialGroup()

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addComponent(jButton16)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton18)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton19)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton27, javax.swing.GroupLayout.DEFAULT_SIZE,

51, Short.MAX_VALUE))

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

Page 39: culadora cientifica en java

                                    .addComponent(jButton23, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE)

                                    .addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE,

69, Short.MAX_VALUE))

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                                    .addGroup(jPanel1Layout.createSequentialGroup()

                                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                                            .addComponent(jButton14

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

                                            .addComponent(jButton11

,javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,

68, Short.MAX_VALUE)

                                            .addComponent(jButton5, 0, 0, Short.MAX_VALUE))

                                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.TRAILING)

                                            .addComponent(jButton6

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

                                            .addComponent(jButton15

, javax.swing.GroupLayout.Alignment.LEADING,javax.swing.GroupLayout.DEFAULT_SIZE, 67,

Short.MAX_VALUE)

                                            .addComponent(jButton21

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

                                    .addGroup(jPanel1Layout.createSequentialGroup()

                                        .addComponent(jButton2

Page 40: culadora cientifica en java

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

                                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                        .addComponent(jButton3

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

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

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                            .addComponent(jButton20, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Short.MAX_VALUE)

                            .addComponent(jButton22, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Short.MAX_VALUE)

                            .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Short.MAX_VALUE)

                            .addComponent(jButton8

, javax.swing.GroupLayout.Alignment.TRAILING,javax.swing.GroupLayout.DEFAULT_SIZE,

59, Short.MAX_VALUE)

                            .addComponent(jButton9, javax.swing.GroupLayout.Alignment.TRAILING,

0, 0, Short.MAX_VALUE)

                            .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 59,

Short.MAX_VALUE)))

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addComponent(jButton25, javax.swing.GroupLayout.DEFAULT_SIZE,

55, Short.MAX_VALUE)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton26, javax.swing.GroupLayout.DEFAULT_SIZE,

55, Short.MAX_VALUE)

                                .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton24, javax.swing.GroupLayout.DEFAULT_SIZE,

67, Short.MAX_VALUE)

                                .addPreferredGap

Page 41: culadora cientifica en java

(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                                .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE,

68,javax.swing.GroupLayout.PREFERRED_SIZE))

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addGap(18, 18, 18)

                                .addComponent(txt, javax.swing.GroupLayout.PREFERRED_SIZE,

238,javax.swing.GroupLayout.PREFERRED_SIZE)))

                        .addGap(18, 18, 18)))

                .addContainerGap())

        );

        jPanel1Layout.setVerticalGroup(

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(txt, javax.swing.GroupLayout.PREFERRED_SIZE,

29,javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addGap(17, 17, 17)

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton26)

                            .addComponent(jButton25)

                            .addComponent(jButton24)))

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

                        .addComponent(jButton12)))

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

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE,

23,javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jButton18)

                    .addComponent(jButton19)

Page 42: culadora cientifica en java

                    .addComponent(jButton27)

                    .addComponent(jButton22))

                .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(jPanel1Layout.createSequentialGroup()

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

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton20)

                            .addComponent(jButton13)

                            .addComponent(jButton14)

                            .addComponent(jButton15))

                        .addGap(35, 35, 35)

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton1)

                            .addComponent(jButton2)

                            .addComponent(jButton3))

                        .addPreferredGap

(javax.swing.LayoutStyle.ComponentPlacement.RELATED,javax.swing.GroupLayout.DEFAUL

T_SIZE, Short.MAX_VALUE)

                        .addComponent(jButton17)

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

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton23)

                            .addComponent(jButton21)

                            .addComponent(jButton11)))

                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

jPanel1Layout.createSequentialGroup()

                        .addGap(35, 35, 35)

                        .addGroup(jPanel1Layout.createParallelGroup

(javax.swing.GroupLayout.Alignment.BASELINE)

                            .addComponent(jButton7)

                            .addComponent(jButton4)

                            .addComponent(jButton6)

Page 43: culadora cientifica en java

                            .addComponent(jButton5))

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

                        .addComponent(jButton8)

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

                        .addComponent(jButton9)

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

                        .addComponent(jButton10)))

                .addContainerGap())

        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

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

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

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

                .addComponent(jPanel1

, javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, javax

.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );

        layout.setVerticalGroup(

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

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

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

                .addComponent(jPanel1

, javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE, javax

.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );

        pack();

    }// </editor-fold>

public double acum;

public double valor;

public double no;

Page 44: culadora cientifica en java

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

    if (no>0)

    {

      txt.setText(“”); 

       txt.setText(txt.getText()+ String.valueOf(1));

       no=0;

       }

    else{

        txt.setText(txt.getText()+ String.valueOf(1));

   

    }

   

    }                                       

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

{                                        

    if (no>0)

    {

      txt.setText(“”);

       txt.setText(txt.getText()+ String.valueOf(2));

       no=0;

       }

    else{

        txt.setText(txt.getText()+ String.valueOf(2));

  

    }

   

    }                                       

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

{                                        

    if (no>0)

    {

      txt.setText(“”);

       txt.setText(txt.getText()+ String.valueOf(3));

       no=0;

       }

Page 45: culadora cientifica en java

    else{

        txt.setText(txt.getText()+ String.valueOf(3));

   

    }

   

    }                                       

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

    if (no>0)

    {

      txt.setText(“”);

      txt.setText(txt.getText()+ String.valueOf(4));

      no=0;

       }

    else{

        txt.setText(txt.getText()+ String.valueOf(4));

   

    }

   

    }                                       

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

     if (no>0)

    {

      txt.setText(“”);

      txt.setText(txt.getText()+ String.valueOf(5));

      no=0;

    }

    else

    {

       txt.setText(txt.getText()+ String.valueOf(5));

   

    }

    

    }                                       

Page 46: culadora cientifica en java

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

    if (no>0)

    {

      txt.setText(“”);

      txt.setText(txt.getText()+ String.valueOf(6));

       no=0;

    }

    else

    {

      txt.setText(txt.getText()+ String.valueOf(6));

   

    }

  

    }                                       

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

          Class_cal Obj_calc=new Class_cal();

  

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

Page 47: culadora cientifica en java

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=1;

   

    }                                       

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

   

if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }                                        

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

   

   

    }

         valor=0;

Page 48: culadora cientifica en java

         no=1;

    }

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        txt.setText(“”);

        acum=0;

        valor=0;

    }                                        

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

        Class_cal Obj_calc=new Class_cal();

 

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

 if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

  if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Dividir()+””);

    }

  else

        acum=Double.parseDouble (txt.getText());

        txt.setText(“”);

Page 49: culadora cientifica en java

        valor=2;

    }                                       

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt)

{                                        

        Class_cal Obj_calc=new Class_cal();

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=3;

    }                                       

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

       Class_cal Obj_calc=new Class_cal();

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

Page 50: culadora cientifica en java

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=4;

    }                                        

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

    if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(7));

      no=0;

    }

    else

    {

     txt.setText(txt.getText()+ String.valueOf(7));

   

    }

    }                                        

Page 51: culadora cientifica en java

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

    if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(8));

     no=0;

    }

    else

    {

     txt.setText(txt.getText()+ String.valueOf(8));

    

    }

    }                                        

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

    if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(9));

     no=0;

    }

    else

    {

     txt.setText(txt.getText()+ String.valueOf(9));

    

    }

    }                                        

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

   if (no>0)

    {

     txt.setText(“”);

     txt.setText(txt.getText()+ String.valueOf(0));

     no=0;

    }

Page 52: culadora cientifica en java

    else

    {

     txt.setText(txt.getText()+ String.valueOf(0));

    

    }

    }                                        

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.seno()+””);

    }                                        

    private void jButton18ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

          Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.coseno()+””);

    }                                        

    private void jButton19ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

           Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.tangente()+””);

    }                                        

    private void jButton20ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

           Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.factorial()+””);

    }                                        

    private void jButton22ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

           Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.Raiz()+””);

    }                                        

Page 53: culadora cientifica en java

    private void jButton23ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        String cadena;

        int punto;

        cadena = txt.getText();

        punto = cadena.indexOf(‘.’);

        if (punto==-1)

         {

          txt.setText(txt.getText()+(“.”));

         }

    }                                        

    private void jButton24ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        String cadena = txt.getText();

        if(!txt.equals(“”))

        txt.setText(cadena.substring(0, cadena.length() – 1));

    }                                        

    private void jButton21ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        txt.setText(String.valueOf(“3.14″));

    }                                        

    private void jButton25ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.cuadrado()+””);

    }                                        

    private void jButton26ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

        Class_cal Obj_calc=new Class_cal();

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.cubo()+””);

    }                                        

    private void jButton27ActionPerformed(java.awt.event.ActionEvent evt)

{                                         

         Class_cal Obj_calc=new Class_cal();

Page 54: culadora cientifica en java

      Obj_calc.Setn1(Double.parseDouble(txt.getText()));

      txt.setText(Obj_calc.cotangente()+””);

    }                                        

    private void jButton7KeyPressed(java.awt.event.KeyEvent evt) {                                   

         Class_cal Obj_calc=new Class_cal();

 if (valor==1){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Sumar()+””);

}

 if (valor==2){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Restar()+””);

    }

   if (valor==3){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

        txt.setText(Obj_calc.Multiplicar()+””);

    }

    if (valor==4){

        Obj_calc.Setn2(Double.parseDouble(txt.getText()));

        Obj_calc.Setn1(acum);

                txt.setText(Obj_calc.Dividir()+””);

    }

    else

            acum=Double.parseDouble (txt.getText());

            txt.setText(“”);

        valor=1;

   

    }                                  

    /**

    * @param args the command line arguments

    */

    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

Page 55: culadora cientifica en java

            public void run() {

                new form_cal().setVisible(true);

            }

        });

    }

    // Variables declaration – do not modify

    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton10;

    private javax.swing.JButton jButton11;

    private javax.swing.JButton jButton12;

    private javax.swing.JButton jButton13;

    private javax.swing.JButton jButton14;

    private javax.swing.JButton jButton15;

    private javax.swing.JButton jButton16;

    private javax.swing.JButton jButton17;

    private javax.swing.JButton jButton18;

    private javax.swing.JButton jButton19;

    private javax.swing.JButton jButton2;

    private javax.swing.JButton jButton20;

    private javax.swing.JButton jButton21;

    private javax.swing.JButton jButton22;

    private javax.swing.JButton jButton23;

    private javax.swing.JButton jButton24;

    private javax.swing.JButton jButton25;

    private javax.swing.JButton jButton26;

    private javax.swing.JButton jButton27;

    private javax.swing.JButton jButton3;

    private javax.swing.JButton jButton4;

    private javax.swing.JButton jButton5;

    private javax.swing.JButton jButton6;

    private javax.swing.JButton jButton7;

    private javax.swing.JButton jButton8;

    private javax.swing.JButton jButton9;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JTextField txt;

    // End of variables declaration

Page 56: culadora cientifica en java

    private javax.swing.JButton jButton7;

    private javax.swing.JButton jButton8;

    private javax.swing.JButton jButton9;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JTextField txt;

    // End of variables declaration

Calculadora científica en Java (Codigo Fuente)Hola aquí les dejo una Calculadora Científica y normal en java, desarrollado en Eclipse, espero que sea de Ayuda para sus Dudas:Lo único que tienen que crear una clase con el nombre ProyectoCalculadora y Pegar código, cualquier duda ESTAMOS para ayudarnos saludos.resultado

la parte cientifica

la parte normal

Page 57: culadora cientifica en java

-------------------------------------

import java.awt.*;import java.awt.event.*;import java.math.MathContext;import javax.management.StringValueExp;import javax.swing.*;public class ProyectoCalculadora extends JFrame implements ActionListener {

String tem=""; String texto=""; float b,c; double con; int opcion; JMenuBar contenedor; JMenu ver,edicion,ayuda ; JRadioButtonMenuItem radianes,centimetros; JMenuItem

estandar,cientifica,programador,copiar,pegar,historial,ver_ayuda,acerca_calculadora; JButton jButton1=new JButton("gsm"); JButton jButton2=new JButton("exp"); JButton jButton3=new JButton("ln"); JButton jButton4=new JButton("sin"); JButton jButton5=new JButton("x^y"); JButton jButton6=new JButton("log"); JButton jButton7=new JButton("cos"); JButton jButton8=new JButton("x^3"); JButton jButton9=new JButton("n!"); JButton jButton10=new JButton("tan"); JButton jButton11=new JButton("x^2"); JButton jButton12=new JButton("1/x"); JButton jButton13=new JButton("7"); JButton jButton14=new JButton("8"); JButton jButton15=new JButton("9");

Page 58: culadora cientifica en java

JButton jButton16=new JButton("/"); JButton jButton17=new JButton("4"); JButton jButton18=new JButton("5"); JButton jButton19=new JButton("6"); JButton jButton20=new JButton("*"); JButton jButton21=new JButton("1"); JButton jButton22=new JButton("2"); JButton jButton23=new JButton("3"); JButton jButton24=new JButton("-"); JButton jButton25=new JButton("0"); JButton jButton26=new JButton("+/-"); JButton jButton27=new JButton(","); JButton jButton28=new JButton("+"); JButton jButton29=new JButton("="); JButton jButton30=new JButton("Retroceso"); JButton jButton31=new JButton("CE"); JButton jButton32=new JButton("C"); JButton jButton33=new JButton("sq"); JButton jButton34=new JButton("%"); JButton jButton35=new JButton("."); JTextField jTextField1=new JTextField(); // iniciar evento=new iniciar(); public ProyectoCalculadora(String nombre) { super(nombre); iniciarControles(); } public void iniciarControles() { //menu ver contenedor=new JMenuBar(); ver =new JMenu("Ver"); edicion=new JMenu("Edicion"); ayuda =new JMenu("Ayuda"); //creando las item estandar =new JMenuItem("Estandar"); cientifica =new JMenuItem("Cientifica"); programador =new JMenuItem("Programador"); copiar =new JMenuItem("Copiar Ctr+c"); pegar =new JMenuItem("Pegar Ctr+v"); historial =new JMenuItem("Historial"); ver_ayuda =new JMenuItem("Ver Ayuda"); acerca_calculadora =new JMenuItem("Acerca de Calculadora"); //agregando this.setJMenuBar(contenedor); contenedor.add(ver);

Page 59: culadora cientifica en java

contenedor.add(edicion); contenedor.add(ayuda); ver.add(estandar); ver.add(cientifica); ver.add(programador); edicion.add(copiar); edicion.add(pegar); edicion.add(historial); ayuda.add(acerca_calculadora); ayuda.add(ver_ayuda); //radioButton radianes =new JRadioButtonMenuItem("Radianes"); centimetros=new JRadioButtonMenuItem("Centimetros"); radianes.setBounds(50,100,80,45); radianes.setBackground(Color.LIGHT_GRAY); centimetros.setBounds(150,100,90,45); centimetros.setBackground(Color.LIGHT_GRAY); jTextField1.setBounds(50,50,405,35); jButton1.setBounds(50,150,60,25); jButton2.setBounds(115,150,60,25); jButton3.setBounds(180,150,60,25); jButton4.setBounds(50,180,60,25); jButton5.setBounds(115,180,60,25); jButton6.setBounds(180,180,60,25); jButton7.setBounds(50,210,60,25); jButton8.setBounds(115,210,60,25); jButton9.setBounds(180,210,60,25); jButton10.setBounds(50,240,60,25); jButton11.setBounds(115,240,60,25); jButton12.setBounds(180,240,60,25); //button retrocesos

jButton30.setBounds(260,95,93,25); jButton31.setBounds(356,95,50,25); jButton32.setBounds(409,95,44,25); //button numericos jButton13.setBounds(260,125,45,25); jButton14.setBounds(310,125,45,25); jButton15.setBounds(360,125,45,25); jButton16.setBounds(410,125,45,25); jButton17.setBounds(260,155,45,25); jButton18.setBounds(310,155,45,25); jButton19.setBounds(360,155,45,25); jButton20.setBounds(410,155,45,25); jButton21.setBounds(260,185,45,25); jButton22.setBounds(310,185,45,25);

Page 60: culadora cientifica en java

jButton23.setBounds(360,185,45,25); jButton24.setBounds(410,185,45,25); jButton25.setBounds(260,215,45,25); jButton26.setBounds(308,215,50,25); jButton27.setBounds(360,215,45,25); jButton28.setBounds(410,215,45,25); jButton29.setBounds(410,245,42,25); this.getContentPane().add(jTextField1); this.getContentPane().add(radianes); this.getContentPane().add(centimetros); this.getContentPane().add(jButton1); this.getContentPane().add(jButton2); this.getContentPane().add(jButton3); this.getContentPane().add(jButton4); this.getContentPane().add(jButton5); this.getContentPane().add(jButton6); this.getContentPane().add(jButton7); this.getContentPane().add(jButton8); this.getContentPane().add(jButton9); this.getContentPane().add(jButton10); this.getContentPane().add(jButton11); this.getContentPane().add(jButton12); this.getContentPane().add(jButton13); this.getContentPane().add(jButton14); this.getContentPane().add(jButton15); this.getContentPane().add(jButton16); this.getContentPane().add(jButton17); this.getContentPane().add(jButton18); this.getContentPane().add(jButton19); this.getContentPane().add(jButton20); this.getContentPane().add(jButton21); this.getContentPane().add(jButton22); this.getContentPane().add(jButton23); this.getContentPane().add(jButton24); this.getContentPane().add(jButton25); this.getContentPane().add(jButton26); this.getContentPane().add(jButton27); this.getContentPane().add(jButton28); this.getContentPane().add(jButton29); this.getContentPane().add(jButton30); this.getContentPane().add(jButton31); this.getContentPane().add(jButton32); this.getContentPane().add(jButton33); this.getContentPane().add(jButton34); this.getContentPane().add(jButton35); //poniendo al evento

Page 61: culadora cientifica en java

jButton1.addActionListener(this); jButton2.addActionListener(this); jButton3.addActionListener(this); jButton4.addActionListener(this); jButton5.addActionListener(this); jButton6.addActionListener(this); jButton7.addActionListener(this); jButton8.addActionListener(this); jButton9.addActionListener(this); jButton10.addActionListener(this); jButton11.addActionListener(this); jButton12.addActionListener(this); jButton13.addActionListener(this); jButton14.addActionListener(this); jButton15.addActionListener(this); jButton16.addActionListener(this); jButton17.addActionListener(this); jButton18.addActionListener(this); jButton19.addActionListener(this); jButton20.addActionListener(this); jButton21.addActionListener(this); jButton22.addActionListener(this); jButton23.addActionListener(this); jButton24.addActionListener(this); jButton25.addActionListener(this); jButton26.addActionListener(this); jButton27.addActionListener(this); jButton28.addActionListener(this); jButton29.addActionListener(this); jButton30.addActionListener(this); jButton31.addActionListener(this); jButton32.addActionListener(this); jButton33.addActionListener(this); jButton35.addActionListener(this); ver_ayuda.addActionListener(this); //para los menus cientifica.addActionListener(this); estandar.addActionListener(this); copiar.addActionListener(this); pegar.addActionListener(this); this.setBounds(500,100,475,335); this.setResizable(isMaximumSizeSet());//desactiva opcion maximizar this.getContentPane().setBackground(Color.LIGHT_GRAY); this.setLayout(null); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Page 62: culadora cientifica en java

} public static void main(String[] args) {

new ProyectoCalculadora("Calculadora"); }// iniciar implements ActionListener para los eventos

public void actionPerformed(ActionEvent e) {

jTextField1.setFocusable(isFocusable());//desactiva el cursor al ingresar un valor

if(e.getSource()==ProyectoCalculadora.this.jButton3) {

b=Float.parseFloat(jTextField1.getText()); jTextField1.setText("");

jTextField1.setText(String.valueOf(Math.log(b)));//lnc=0;

} if(e.getSource()==ProyectoCalculadora.this.jButton4) {

b=Float.parseFloat(jTextField1.getText()); con=(b*Math.PI)/180;//convercion de radianes a

sexagesimalesjTextField1.setText("");

jTextField1.setText(String.valueOf(Math.sin(con)));c=0;con=0;

} if(e.getSource()==ProyectoCalculadora.this.jButton5) {

b=Float.parseFloat(jTextField1.getText()); jTextField1.setText("");opcion=5;tem="";

} if(e.getSource()==ProyectoCalculadora.this.jButton6) {

b=Float.parseFloat(jTextField1.getText()); jTextField1.setText("");

jTextField1.setText(String.valueOf(Math.log10(b)));c=0;

} if(e.getSource()==ProyectoCalculadora.this.jButton7) {

Page 63: culadora cientifica en java

b=Float.parseFloat(jTextField1.getText()); con=(b*Math.PI)/180;jTextField1.setText("");

jTextField1.setText(String.valueOf(Math.cos(con)));con=0;c=0;

} if(e.getSource()==ProyectoCalculadora.this.jButton8) {

b=Float.parseFloat(jTextField1.getText()); jTextField1.setText("");

jTextField1.setText(String.valueOf(Math.pow(b,3)));c=0;

}

if(e.getSource()==ProyectoCalculadora.this.jButton9)//factorial { double k=1;

b=Float.parseFloat(jTextField1.getText()); jTextField1.setText("");

for (int i = 1; i <=b; i++) {

k=k*i;}jTextField1.setText(String.valueOf(k));

} if(e.getSource()==ProyectoCalculadora.this.jButton10) {

b=Float.parseFloat(jTextField1.getText()); con=(b*Math.PI)/180;//convercion de grados a

radianesjTextField1.setText("");

jTextField1.setText(String.valueOf(Math.tan(con)));con=0;c=0;

} if(e.getSource()==ProyectoCalculadora.this.jButton11) {

b=Float.parseFloat(jTextField1.getText()); jTextField1.setText("");

jTextField1.setText(String.valueOf(Math.pow(b,2)));c=0;

} if(e.getSource()==ProyectoCalculadora.this.jButton12)

Page 64: culadora cientifica en java

{b=Float.parseFloat(jTextField1.getText()); jTextField1.setText("");if(b!=0)jTextField1.setText(String.valueOf(1/b));else

jTextField1.setText("error"); } if(e.getSource()==ProyectoCalculadora.this.jButton13) {

if(jTextField1.getText()=="") {

jButton13.setText(jButton13.getText());tem=jButton13.getText();

} else {

jTextField1.setText(tem+jButton13.getText());

tem+=jButton13.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton14) {

if(jTextField1.getText()=="") {

jButton14.setText(jButton14.getText());tem=jButton14.getText();

} else {

jTextField1.setText(tem+jButton14.getText());

tem+=jButton14.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton15) {

if(jTextField1.getText()=="") {

jButton15.setText(jButton15.getText());tem=jButton15.getText();

} else {

jTextField1.setText(tem+jButton15.getText());

tem+=jButton15.getText(); }

Page 65: culadora cientifica en java

} if(e.getSource()==ProyectoCalculadora.this.jButton17) {

if(jTextField1.getText()=="") {

jButton17.setText(jButton17.getText());tem=jButton17.getText();

} else {

jTextField1.setText(tem+jButton17.getText());

tem+=jButton17.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton18) {

if(jTextField1.getText()=="") {

jButton18.setText(jButton18.getText());tem=jButton18.getText();

} else {

jTextField1.setText(tem+jButton18.getText());

tem+=jButton18.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton19) {

if(jTextField1.getText()=="") {

jButton19.setText(jButton19.getText());tem=jButton19.getText();

} else {

jTextField1.setText(tem+jButton19.getText());

tem+=jButton19.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton21) {

if(jTextField1.getText()=="") {

jButton21.setText(jButton21.getText());tem=jButton21.getText();

} else

Page 66: culadora cientifica en java

{

jTextField1.setText(tem+jButton21.getText()); tem+=jButton21.getText();

} } if(e.getSource()==ProyectoCalculadora.this.jButton22) {

if(jTextField1.getText()=="") {

jButton22.setText(jButton22.getText());tem=jButton22.getText();

} else {

jTextField1.setText(tem+jButton22.getText());

tem+=jButton22.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton23) {

if(jTextField1.getText()=="") {

jButton23.setText(jButton23.getText());tem=jButton23.getText();

} else {

jTextField1.setText(tem+jButton23.getText());

tem+=jButton23.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton25) {

if(jTextField1.getText()=="") {

jButton25.setText(jButton25.getText());tem=jButton25.getText();

} else {

jTextField1.setText(tem+jButton25.getText());

tem+=jButton25.getText(); }

} if(e.getSource()==ProyectoCalculadora.this.jButton26)

Page 67: culadora cientifica en java

{ float tem6; tem6=-Float.valueOf(jTextField1.getText()); jTextField1.setText(String.valueOf(tem6));

} if(e.getSource()==jButton30)//button retroceso {

String tem2=""; for (int i = 0; i < jTextField1.getText().length()-1; i++) {

tem2=tem2+jTextField1.getText().charAt(i); }

jTextField1.setText(tem2); tem=tem2;

}

if(e.getSource()==ProyectoCalculadora.this.jButton28)//operador sumar {

b=Float.parseFloat(jTextField1.getText()); tem="";

jTextField1.setText(""); opcion=1;

}

if(e.getSource()==ProyectoCalculadora.this.jButton24)//operador restar {

b=Float.parseFloat(jTextField1.getText()); tem="";

jTextField1.setText(""); opcion=2;

}

if(e.getSource()==ProyectoCalculadora.this.jButton20)//operador multiplicar

{

b=Float.parseFloat(jTextField1.getText()); tem="";

jTextField1.setText(""); opcion=3;

}

if(e.getSource()==ProyectoCalculadora.this.jButton16)//operador dividir

Page 68: culadora cientifica en java

{

b=Float.parseFloat(jTextField1.getText()); tem="";

jTextField1.setText(""); opcion=4;

}

if(e.getSource()==ProyectoCalculadora.this.jButton33)//operador raiz {

b=Float.parseFloat(jTextField1.getText());

jTextField1.setText(String.valueOf(Math.sqrt(b))); b=0;

}

if(e.getSource()==ProyectoCalculadora.this.jButton35)//operador raiz {

tem=jTextField1.getText(); jTextField1.setText(tem+"."); tem+=jTextField1.getText();

} if(e.getSource()==ver_ayuda ||

e.getSource()==acerca_calculadora) {

JOptionPane.showMessageDialog(null,"Proyecto de Calculadora Cientifica Algoritmica III"+"\n"+" Autor:Alejandro Hurtado Chacñama"+"\n"+"Todos los Derechos reservados");

} if(e.getSource()==copiar)//copiar el codigo {

jTextField1.copy(); } if(e.getSource()==pegar)//pegar el codigo {

jTextField1.paste(); }

if(e.getSource()==ProyectoCalculadora.this.jButton29)//realizando las operaciones

{ c= Float.parseFloat(jTextField1.getText()); switch (opcion) {

Page 69: culadora cientifica en java

case 1:jTextField1.setText("");

jTextField1.setText(String.valueOf(b+c));break;

case 2: jTextField1.setText("");

jTextField1.setText(String.valueOf(b-c));break;

case 3: jTextField1.setText("");

jTextField1.setText(String.valueOf(b*c)); break;

case 4: if( c!=0) { jTextField1.setText("");

jTextField1.setText(String.valueOf(b/c)); } else jTextField1.setText("error"); break; case 5: jTextField1.setText(""); jTextField1.setText(String.valueOf(Math.pow(b, c)));//x¨y break;

default:jTextField1.setText("Valor no Admitido ");

} }

if(e.getSource()==ProyectoCalculadora.this.jButton31)//borra todos los datos de Jtexfield

{jTextField1.setText("0");tem="";c=0;b=0;opcion=0;con=0;

}

if(e.getSource()==ProyectoCalculadora.this.jButton32)//borra todos los datos de Jtexfield

{jTextField1.setText("0");tem="";

Page 70: culadora cientifica en java

c=0;b=0;opcion=0;con=0;

} //aplicando la calculadora cientifica y normal if(e.getSource()==estandar) {

jButton1.setVisible(false); jButton2.setVisible(false); jButton3.setVisible(false); jButton4.setVisible(false); jButton5.setVisible(false); jButton6.setVisible(false); jButton7.setVisible(false); jButton8.setVisible(false); jButton9.setVisible(false); jButton10.setVisible(false); jButton11.setVisible(false); jButton27.setVisible(false); centimetros.setVisible(false); radianes.setVisible(false); this.setBounds(500,100,300,300); jTextField1.setBounds(10,50,260,35); jButton30.setBounds(10,90,95,25); jButton31.setBounds(110,90,50,25); jButton32.setBounds(165,90,50,25); jButton26.setBounds(220,90,50,25); jButton13.setBounds(10,120,45,25); jButton14.setBounds(60,120,45,25); jButton15.setBounds(110,120,48,25); jButton16.setBounds(165,120,50,25); jButton34.setBounds(220,120,50,25);

jButton17.setBounds(10,150,45,25); jButton18.setBounds(60,150,45,25); jButton19.setBounds(110,150,48,25); jButton20.setBounds(165,150,50,25); jButton12.setBounds(220,150,52,25); jButton21.setBounds(10,180,45,25); jButton22.setBounds(60,180,45,25); jButton23.setBounds(110,180,48,25); jButton24.setBounds(165,180,50,25); jButton33.setBounds(220,180,52,25); jButton25.setBounds(10,210,95,25); jButton35.setBounds(110,210,50,25);

Page 71: culadora cientifica en java

jButton28.setBounds(165,210,50,25); jButton29.setBounds(220,210,52,25); jButton12.setVisible(true);

jButton33.setVisible(true); jButton34.setVisible(true);

} else

if(e.getSource()==cientifica) {

// estandar.setVisible(false); jButton1.setVisible(true); jButton2.setVisible(true); jButton3.setVisible(true); jButton4.setVisible(true); jButton5.setVisible(true); jButton6.setVisible(true); jButton7.setVisible(true); jButton8.setVisible(true); jButton9.setVisible(true); jButton10.setVisible(true); jButton11.setVisible(true); jButton12.setVisible(true); jButton27.setVisible(true); jButton33.setVisible(false); jButton34.setVisible(false); centimetros.setVisible(true); radianes.setVisible(true);

jTextField1.setBounds(50,50,405,35); jButton12.setBounds(180,240,60,25); jButton13.setBounds(260,125,45,25);

jButton14.setBounds(310,125,45,25); jButton15.setBounds(360,125,45,25); jButton16.setBounds(410,125,45,25); jButton17.setBounds(260,155,45,25); jButton18.setBounds(310,155,45,25); jButton19.setBounds(360,155,45,25); jButton20.setBounds(410,155,45,25); jButton21.setBounds(260,185,45,25); jButton22.setBounds(310,185,45,25); jButton23.setBounds(360,185,45,25); jButton24.setBounds(410,185,45,25); jButton25.setBounds(260,215,45,25); jButton26.setBounds(308,215,50,25); jButton27.setBounds(360,215,45,25); jButton28.setBounds(410,215,45,25);

Page 72: culadora cientifica en java

jButton29.setBounds(410,245,42,25); jButton30.setBounds(260,95,93,25); jButton31.setBounds(356,95,50,25); jButton32.setBounds(409,95,44,25); this.setBounds(500,100,475,335);

} };

};