ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Calculadora científica Java


Enviado por   •  25 de Noviembre de 2019  •  Prácticas o problemas  •  4.408 Palabras (18 Páginas)  •  269 Visitas

Página 1 de 18

import javax.swing.*;

import javax.swing.JButton;

import java.awt.*;

import java.awt.event.*;

import java.math.MathContext;

public class calculadora extends JFrame implements ActionListener

{

public JPanel panel;

JButton b1 = new JButton();

JButton b2 = new JButton();

JButton b3 = new JButton();

JButton b4 = new JButton();

JButton b5 = new JButton();

JButton b6 = new JButton();

JButton b7 = new JButton();

JButton b8 = new JButton();

JButton b9 = new JButton();

JButton b10 = new JButton();

JButton b11 = new JButton();

JButton b12 = new JButton();

JButton b13 = new JButton();

JButton b14 = new JButton();

JButton b15 = new JButton();

JButton b16 = new JButton();

JButton b17 = new JButton();

JButton b18 = new JButton();

JButton b19 = new JButton();

JButton b20 = new JButton();

JButton b21 = new JButton();

JButton b22 = new JButton();

JButton b23 = new JButton();

JButton b24 = new JButton();

JButton b25 = new JButton();

JButton b26 = new JButton();

JButton b27 = new JButton();

JButton b28 = new JButton();

JButton b29 = new JButton();

JButton b30 = new JButton();

JButton b31 = new JButton();

JButton sqrt = new JButton();

JButton sqrt2 = new JButton();

JButton adelante = new JButton();

JButton atras = new JButton();

JTextField caja1 = new JTextField ();

double num1;

double num2;

double angulos;

double rad;

String op;

public calculadora () {

setSize(685,605); //se estabece el tamaño de la ventana

setDefaultCloseOperation(EXIT_ON_CLOSE); //close on exit

setTitle("Calculadora Científica"); //se establece el título

setLocationRelativeTo(null); //se establece la ventana en el centro

iniciarcomponentes (); //activo mis componentes

}

private void iniciarcomponentes () {

colocarpanel(); //iniciamos el panel

crearbotones(); //iniciamos los botones

colocarcajadetexto();

}

private void colocarpanel() {

panel = new JPanel (); //crear mi panel

getContentPane().add(panel); //agregar el panel

panel.setLayout(null);

}

private void crearbotones() {

b1.setText("Sin"); //establecer texto al botón

b1.setBounds(50, 140, 90, 60); //definir posición del botón

b1.addActionListener(this); //agregamos oyente de acción

// creamos botón 2

b2.setText("Cos");

b2.setBounds(150, 140, 90, 60);

b2.addActionListener(this);

//creamos botón 3

b3.setText("Tan");

b3.setBounds(250, 140, 90, 60);

b3.addActionListener(this);

//creamos botón 4

b4.setText("Sin -1");

b4.setBounds(50, 210, 90, 60);

b4.addActionListener(this);

//creamos botón 5

b5.setText("Cos -1");

b5.setBounds(150, 210, 90, 60);

b5.addActionListener(this);

//creamos botón 6

b6.setText("Tan -1");

b6.setBounds(250, 210, 90, 60);

b6.addActionListener(this);

//creamos botón 7

b7.setText("Pi");

b7.setBounds(50, 280, 90, 130);

b7.addActionListener(this);

//creamos botón 8

b8.setText("Ln");

b8.setBounds(150, 280, 90, 130);

b8.addActionListener(this);

//creamos botón 9

b9.setText("Log");

b9.setBounds(250, 280, 90, 130);

b9.addActionListener(this);

//creamos botón 10

b10.setText("1/x");

b10.setBounds(50, 420, 90, 60);

b10.addActionListener(this);

//creamos botón 11

b11.setText("x^2");

b11.setBounds(150, 420, 90, 60);

b11.addActionListener(this);

//creamos botón 12

b12.setText("x^x");

b12.setBounds(250, 420, 90, 60);

b12.addActionListener(this);

//creamos botón raíz cudrada

sqrt.setText("sqrt");

sqrt.setBounds(50, 490, 140, 60);

sqrt.addActionListener(this);

//creamos botón raíz

sqrt2.setText("sqrt^x");

sqrt2.setBounds(200, 490, 140, 60);

sqrt2.addActionListener(this);

//creamos botón 13

b13.setText("c");

b13.setBounds(350, 140, 60, 60);

b13.addActionListener(this);

//creamos botón 14

b14.setText("ce");

b14.setBounds(420, 140, 60, 60);

b14.addActionListener(this);

//creamos botón 15

b15.setText("/");

b15.setBounds(490, 140, 60, 60);

b15.addActionListener(this);

//creamos botón 16

b16.setText("%");

b16.setBounds(560, 140, 60, 60);

b16.addActionListener(this);

//creamos botón 17

b17.setText("1");

b17.setBounds(350, 210, 60, 60);

b17.addActionListener(this);

//creamos botón 18

b18.setText("2");

b18.setBounds(420, 210, 60, 60);

b18.addActionListener(this);

//creamos botón 19

b19.setText("3");

b19.setBounds(490, 210, 60, 60);

b19.addActionListener(this);

//creamos botón 20

b20.setText("4");

b20.setBounds(350, 280, 60, 60);

b20.addActionListener(this);

//creamos botón 21

b21.setText("5");

b21.setBounds(420, 280, 60, 60);

b21.addActionListener(this);

//creamos botón 22

b22.setText("6");

b22.setBounds(490, 280, 60, 60);

b22.addActionListener(this);

//creamos botón 23

b23.setText("7");

b23.setBounds(350, 350, 60, 60);

b23.addActionListener(this);

//creamos botón 24

b24.setText("8");

b24.setBounds(420, 350, 60, 60);

b24.addActionListener(this);

//creamos botón 25

...

Descargar como (para miembros actualizados) txt (15 Kb) pdf (47 Kb) docx (15 Kb)
Leer 17 páginas más »
Disponible sólo en Clubensayos.com