Sunteți pe pagina 1din 15

CALCULADORA CIENTFICA EN JAVA Hola aqu les dejo una Calculadora Cientfica 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 cdigo, cualquier duda ESTAMOS para ayudarnos saludos. --------------------import java.awt .*; importacin java.awt.event .*; importacin java.math.MathContext; importacin javax.management.StringValueExp; importacin javax.swing .*; public class ProyectoCalculadora extends JFrame implements ActionListener { Cadena de temperatura = ""; String texto = ""; b flotador, c; Con doble; int opcion; JMenuBar contenedor; ver JMenu, edicion, Ayuda; radianes JRadioButtonMenuItem, centimetros; JMenuItem estandar, Cientfica, programador, Copiar, Pegar, ver_ayuda historial, acerca_calculadora; JButton jButton1 = new JButton ("GSM"); JButton jButton2 = new JButton ("CAD"); JButton jButton3 = new JButton ("En"); JButton jButton4 = new JButton ("pecado"); 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 ("bronceado"); 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"); 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 ("cuadrado"); JButton jButton34 = new JButton ("%"); JButton jButton35 = new JButton (".");

JTextField jTextField1 = new JTextField (); / / Evento Iniciar Iniciar = new (); pblica ProyectoCalculadora (Nombre de cadena) { super (nombre); iniciarControles (); } iniciarControles public void () { / / Men ver JMenuBar contenedor = new (); ver = JMenu nueva ("Ver"); edicion = new JMenu ("Edicin"); Ayuda = new JMenu ("Ayuda"); / / Las Creando tema JMenuItem nuevo estandar = ("Estandar"); Cientfica = JMenuItem nuevo ("Cientfica"); programador = JMenuItem nuevo ("Programador"); Copiar = JMenuItem nuevo ("Copiar Ctr + c"); Pegar = JMenuItem nuevo ("Pegar Ctr + v"); historial = JMenuItem nuevo ("Historial"); ver_ayuda JMenuItem nuevo = ("Ver Ayuda"); acerca_calculadora JMenuItem nuevo = ("Acerca de Calculadora"); / / Agregando this.setJMenuBar (contenedor); contenedor.add (v.); contenedor.add (edicion); contenedor.add (Ayuda); ver.add (estandar); ver.add (Cientfica); ver.add (programador); edicion.add (Copiar); edicion.add (Pegar);

edicion.add (historial); ayuda.add (acerca_calculadora); ayuda.add (ver_ayuda); / / RadioButton radianes = JRadioButtonMenuItem nueva ("radianes"); centimetros = JRadioButtonMenuItem nueva ("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); / / Retrocesos botn jButton30.setBounds (260,95,93,25); jButton31.setBounds (356,95,50,25); jButton32.setBounds (409,95,44,25); / / Numericos botn 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); 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 jButton1.addActionListener (este); jButton2.addActionListener (este); jButton3.addActionListener (este);

jButton4.addActionListener (este); jButton5.addActionListener (este); jButton6.addActionListener (este); jButton7.addActionListener (este); jButton8.addActionListener (este); jButton9.addActionListener (este); jButton10.addActionListener (este); jButton11.addActionListener (este); jButton12.addActionListener (este); jButton13.addActionListener (este); jButton14.addActionListener (este); jButton15.addActionListener (este); jButton16.addActionListener (este); jButton17.addActionListener (este); jButton18.addActionListener (este); jButton19.addActionListener (este); jButton20.addActionListener (este); jButton21.addActionListener (este); jButton22.addActionListener (este); jButton23.addActionListener (este); jButton24.addActionListener (este); jButton25.addActionListener (este); jButton26.addActionListener (este); jButton27.addActionListener (este); jButton28.addActionListener (este); jButton29.addActionListener (este); jButton30.addActionListener (este); jButton31.addActionListener (este); jButton32.addActionListener (este); jButton33.addActionListener (este); jButton35.addActionListener (este); ver_ayuda.addActionListener (este); / / Los mens prrafo cientifica.addActionListener (este); estandar.addActionListener (este); copiar.addActionListener (este); pegar.addActionListener (este);

this.setBounds (500100475335); this.setResizable (isMaximumSizeSet ());// desactiva maximizar opcion this.getContentPane () setBackground (Color.LIGHT_GRAY).; this.setLayout (null); this.setVisible (true); this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); } public static void Main (string [] args) {

ProyectoCalculadora nueva ("Calculadora"); } / / Iniciar implementa ActionListener los prr Eventos public void actionPerformed (ActionEvent e) { jTextField1.setFocusable (isFocusable ());// desactiva El valor del cursor sin ingresar al if (e.getSource () == ProyectoCalculadora.this.jButton3) { b = Float.parseFloat (jTextField1.getText ()); (""); JTextField1.setText jTextField1.setText (String.valueOf (Math.log (ln b )));// c = 0; } if (e.getSource () == ProyectoCalculadora.this.jButton4) { b = Float.parseFloat (jTextField1.getText ()); con = (b * Math.PI) / 180 / / de convercion radianes un sexagesimales (""); JTextField1.setText jTextField1.setText (String.valueOf (Matemticas.Sin (con))); c = 0; con = 0; } if (e.getSource () == ProyectoCalculadora.this.jButton5) { b = Float.parseFloat (jTextField1.getText ()); (""); JTextField1.setText opcion = 5; temperatura = ""; } 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) { 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 {K = 1 doble; 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 una radianes (""); JTextField1.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) { b = Float.parseFloat (jTextField1.getText ()); (""); JTextField1.setText if (b! = 0) jTextField1.setText (String.valueOf (1 / b)); ms jTextField1.setText ("Error"); } if (e.getSource () == ProyectoCalculadora.this.jButton13) { if (()=="") jTextField1.getText { jButton13.setText (jButton13.getText ()); = temperatura jButton13.getText ();

} ms { jTextField1.setText (temperatura + jButton13.getText ()); temperatura + jButton13.getText = (); } } if (e.getSource () == ProyectoCalculadora.this.jButton14) { if (()=="") jTextField1.getText { jButton14.setText (jButton14.getText ()); = temperatura jButton14.getText (); } ms { jTextField1.setText (temperatura + jButton14.getText ()); temperatura + jButton14.getText = (); } } If (e.getSource () == ProyectoCalculadora.this.jButton15) { if (()=="") jTextField1.getText { jButton15.setText (jButton15.getText ()); = temperatura jButton15.getText (); } ms { jTextField1.setText (temperatura + jButton15.getText ()); temperatura + jButton15.getText = (); } } If (e.getSource () == ProyectoCalculadora.this.jButton17) { if (()=="") jTextField1.getText { jButton17.setText (jButton17.getText ()); = temperatura jButton17.getText (); } ms { jTextField1.setText (temperatura + jButton17.getText ()); temperatura + jButton17.getText = (); } } If (e.getSource () == ProyectoCalculadora.this.jButton18) { if (()=="") jTextField1.getText { jButton18.setText (jButton18.getText ());

= temperatura jButton18.getText (); } ms { jTextField1.setText (temperatura + jButton18.getText ()); temperatura + jButton18.getText = (); } } If (e.getSource () == ProyectoCalculadora.this.jButton19) { if (()=="") jTextField1.getText { jButton19.setText (jButton19.getText ()); = temperatura jButton19.getText (); } ms { jTextField1.setText (temperatura + jButton19.getText ()); temperatura + jButton19.getText = (); } } If (e.getSource () == ProyectoCalculadora.this.jButton21) { if (()=="") jTextField1.getText { jButton21.setText (jButton21.getText ()); = temperatura jButton21.getText (); } ms { jTextField1.setText (temperatura + jButton21.getText ()); temperatura + jButton21.getText = (); } } If (e.getSource () == ProyectoCalculadora.this.jButton22) { if (()=="") jTextField1.getText { jButton22.setText (jButton22.getText ()); = temperatura jButton22.getText (); } ms { jTextField1.setText (temperatura + jButton22.getText ()); temperatura + jButton22.getText = (); } } If (e.getSource () == ProyectoCalculadora.this.jButton23) { if (()=="") jTextField1.getText {

jButton23.setText (jButton23.getText ()); = temperatura jButton23.getText (); } ms { jTextField1.setText (temperatura + jButton23.getText ()); temperatura + jButton23.getText = (); } } if (e.getSource () == ProyectoCalculadora.this.jButton25) { if (()=="") jTextField1.getText { jButton25.setText (jButton25.getText ()); = temperatura jButton25.getText (); } ms { jTextField1.setText (temperatura + jButton25.getText ()); temperatura + jButton25.getText = (); } } if (e.getSource () == ProyectoCalculadora.this.jButton26) { flotador tem6; tem6 =- Float.valueOf (jTextField1.getText ()); jTextField1.setText (String.valueOf (tem6)); } if (e.getSource () == jButton30) / / Retroceso botn { Tem2 cadena = ""; for (int i = 0; i jTextField1.getText <(), longitud () -1;. i + +) { tem2 = tem2 jTextField1.getText + () charAt (i).; } jTextField1.setText (tem2); = temperatura tem2; } if (e.getSource () == ProyectoCalculadora.this.jButton28) / / Sumar Operador { b = Float.parseFloat (jTextField1.getText ()); temperatura = ""; (""); JTextField1.setText

opcion = 1; } if (e.getSource () == ProyectoCalculadora.this.jButton24) / / Operador RESTAR { b = Float.parseFloat (jTextField1.getText ()); temperatura = ""; (""); JTextField1.setText opcion = 2; } if (e.getSource () == ProyectoCalculadora.this.jButton20) / / Multiplicar Operador { b = Float.parseFloat (jTextField1.getText ()); temperatura = ""; (""); JTextField1.setText opcion = 3; } if (e.getSource () == ProyectoCalculadora.this.jButton16) / / dividir Operador { b = Float.parseFloat (jTextField1.getText ()); temperatura = ""; (""); JTextField1.setText opcion = 4; } if (e.getSource () == ProyectoCalculadora.this.jButton33) / / raiz Operador { b = Float.parseFloat (jTextField1.getText ()); jTextField1.setText (String.valueOf (Math.sqrt (b))); b = 0; } if (e.getSource () == ProyectoCalculadora.this.jButton35) / / raiz Operador { = temperatura jTextField1.getText (); jTextField1.setText (+"."); temperatura temperatura + jTextField1.getText = (); } if (e.getSource () == ver_ayuda | | e.getSource () == acerca_calculadora) { JOptionPane.showMessageDialog (null, "Proyecto de Calculadora Cientfica Algoritmica III" + "\ n" + "Autor: Alejandro Hurtado Chacama" + "\ 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) / / Las Realizando Operaciones { c = Float.parseFloat (jTextField1.getText ()); switch (opcion) { Caso 1: (""); JTextField1.setText jTextField1.setText (String.valueOf (b + c)); break; el caso 2: (""); JTextField1.setText jTextField1.setText (String.valueOf (b-c)); break; caso 3: (""); JTextField1.setText jTextField1.setText (String.valueOf (b * c)); break; Caso 4: if (c! = 0) { (""); JTextField1.setText jTextField1.setText (String.valueOf (b / c)); } ms jTextField1.setText ("Error"); break; Caso 5: (""); JTextField1.setText jTextField1.setText (String.valueOf (Math.pow (b, c )));// x y break; por defecto: jTextField1.setText ("Valor no Admitido"); } } if (e.getSource () == ProyectoCalculadora.this.jButton31) / / Borra de Todos los Datos de Jtexfield { jTextField1.setText ("0"); temperatura = ""; c = 0; b = 0;

opcion = 0; con = 0; } if (e.getSource () == ProyectoCalculadora.this.jButton32) / / Borra de Todos los Datos de Jtexfield { jTextField1.setText ("0"); temperatura = ""; c = 0; b = 0; opcion = 0; con = 0; } / / Aplicando la Calculadora Cientfica 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 (500100300300); 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); jButton28.setBounds (165,210,50,25); jButton29.setBounds (220,210,52,25); jButton12.setVisible (true); jButton33.setVisible (true); jButton34.setVisible (true); } ms if (e.getSource () == Cientfica) { / / 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); 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 (500100475335); } }; };

S-ar putea să vă placă și