Docsity

Código fuente de una calculadora básica en Java, Resúmenes de Computación Paralela y Programación

Vista previa parcial del texto

¡Descarga Código fuente de una calculadora básica en Java y más Resúmenes en PDF de Computación Paralela y Programación solo en Docsity!

Alumno: Irvin Michel Gonzalez vega

Programa de calculadora

CODIGO COMPLETO

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor. / package Calcu; /*
  • @author irvinvega / public class Calculadorabasica extends javax.swing.JFrame { /*
  • Creates new form Calculadorabasica / public Calculadorabasica() { initComponents(); } /*
  • This method is called from within the constructor to initialize the form.
  • WARNING: Do NOT modify this code. The content of this method is always
  • regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { numero1 = new javax.swing.JTextField(); numero2 = new javax.swing.JTextField(); OK = new javax.swing.JButton(); resultado = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMaximumSize(new java.awt.Dimension(400, 330));

.addGap(28, 28, 28) .addComponent(numero2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 166, Short.MAX_VALUE) .addComponent(resultado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); pack(); }// </editor-fold> private void OKActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: int num1 = 0; int num2 = 0; int res = 0; try{ num1 = Integer.parseInt(numero1.getText().toString()); num2 = Integer.parseInt(numero2.getText().toString()); res = num1num2; resultado.setText("Resultado: "+res); // num1 = }catch(Exception e){ System.out.print("\n"+e.toString()); } } /*

  • @param args the command line arguments / public static void main(String args[]) { / Set the Nimbus look and feel / //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> / If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  • For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try {

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Calculadorabasica.class.getName()).log(java.util.logging. Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Calculadorabasica.class.getName()).log(java.util.logging. Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Calculadorabasica.class.getName()).log(java.util.logging. Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Calculadorabasica.class.getName()).log(java.util.logging. Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Calculadorabasica().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton OK; private javax.swing.JTextField numero1; private javax.swing.JTextField numero2; private javax.swing.JTextField resultado; // End of variables declaration }