0% encontró este documento útil (0 votos)
31 vistas6 páginas

Import Javax

Este documento contiene el código Java para una aplicación que realiza cálculos matemáticos básicos (suma, resta, multiplicación y división). La aplicación permite ingresar dos números, seleccionar una operación y calcular el resultado, el cual se muestra en un cuadro de texto. También almacena los datos de cada cálculo en una tabla para futuras consultas.

Cargado por

Brando Ulloa
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
31 vistas6 páginas

Import Javax

Este documento contiene el código Java para una aplicación que realiza cálculos matemáticos básicos (suma, resta, multiplicación y división). La aplicación permite ingresar dos números, seleccionar una operación y calcular el resultado, el cual se muestra en un cuadro de texto. También almacena los datos de cada cálculo en una tabla para futuras consultas.

Cargado por

Brando Ulloa
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 6

import javax.swing.

JOptionPane;

import javax.swing.table.DefaultTableModel;

public class calcular extends javax.swing.JFrame {

String operacion="";

public calcular() {

initComponents();

/*int a=50,b=60,c=0;

c=a+b;

// System.out.println("el total es"+c);

JOptionPane.showMessageDialog(null,"la suma es"+c);

*/

num1.requestFocus();

sumar.setSelected(true);

void restar_numero(){

int a=0,b=0,c=0;

a=Integer.parseInt(num1.getText());

b=Integer.parseInt(num2.getText());

c=a-b;

total.setText(String.valueOf(c) );

operacion="resta";

void sumar_numero(){

int a=0,b=0,c=0;

a=Integer.parseInt(num1.getText());
b=Integer.parseInt(num2.getText());

c=a+b;

total.setText(String.valueOf(c) );

operacion="suma";

void multiplicar_numero(){

int a=0,b=0,c=0;

a=Integer.parseInt(num1.getText());

b=Integer.parseInt(num2.getText());

c=a*b;

total.setText(String.valueOf(c) );

operacion="multiplicacion";

void dividir_numero(){

int a=0,b=0,c=0;

a=Integer.parseInt(num1.getText());

b=Integer.parseInt(num2.getText());

c=a/b;

total.setText(String.valueOf(c) );

operacion="dividir";

void limpiar_datos(){

num1.setText("");

num2.setText("");
total.setText("");

num1.requestFocus();

void agregar_datos(){

DefaultTableModel alvin = (DefaultTableModel)t_numeros.getModel();

//alvin.getDataVector().clear();

String [] registros = new String[4];

registros[0]=num1.getText();

registros[1]=num2.getText();

registros[2]=operacion;

registros[3]=total.getText();

alvin.addRow(registros);

t_numeros.setModel(alvin);
private void calcularActionPerformed(java.awt.event.ActionEvent evt) {

if (sumar.isSelected()){

sumar_numero();

if (restar.isSelected()){

restar_numero();

if (multiplicar.isSelected()){

multiplicar_numero();

if (dividir.isSelected()){

dividir_numero();

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

this.dispose(); // TODO add your handling code here:

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

if (num1.getText().equals("")){

JOptionPane.showMessageDialog(null,"EL NUMERO 1 ESTA EN BLANCO");

num1.requestFocus();

return;

num2.requestFocus(); // TODO add your handling code here:


}

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

if (num2.getText().equals(""))

JOptionPane.showMessageDialog(null,"EL NUMERO 2 ESTA EN BLANCO");

num2.requestFocus();

return; // TODO add your handling code here:

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

limpiar_datos();

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

agregar_datos(); // TODO add your handling code here:

private void t_numerosMouseClicked(java.awt.event.MouseEvent evt) {

int fila=t_numeros.getSelectedRow();

if(fila>=0){

num1.setText(t_numeros.getValueAt(fila, 0).toString());

num2.setText(t_numeros.getValueAt(fila, 1).toString());

if(t_numeros.getValueAt(fila, 2).toString().equals("SUMA")){

sumar.setSelected(true);

if(t_numeros.getValueAt(fila, 2).toString().equals("RESTA")){

restar.setSelected(true);

}
if(t_numeros.getValueAt(fila, 2).toString().equals("MULTIPLICACION")){

multiplicar.setSelected(true);

if(t_numeros.getValueAt(fila, 2).toString().equals("DIVISION")){

dividir.setSelected(true);

total.setText(t_numeros.getValueAt(fila, 3).toString());

También podría gustarte