Está en la página 1de 4

/*

* 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 suma;
/**
*
* @author Recamara
*/
public class InterSuma extends javax.swing.JFrame {
/**
* Creates new form InterSuma
*/
public InterSuma() {
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() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
a = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
b = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
resul = new javax.swing.JLabel();
error = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Ingreso de numeros");
jLabel2.setText("Ingrese el primer numero");
jLabel3.setText("Ingrese el segundo numero");
b.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bActionPerformed(evt);
}
});
jButton1.setText("Sumar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel4.setText("resultado");
error.setForeground(java.awt.Color.red);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createS
equentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX
_VALUE)
.addComponent(jLabel4)
.addGap(44, 44, 44)
.addComponent(resul)
.addGap(26, 26, 26))
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(error)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout
.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAU
LT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addComponent(a))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem
ent.RELATED, 119, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(56, 56, 56))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.TRAILING)
.addComponent(jLabel3, javax.swing.GroupLayout.Align
ment.LEADING)
.addComponent(b, javax.swing.GroupLayout.Alignment.L
EADING, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PRE
FERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, S
hort.MAX_VALUE))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jLabel1)
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jLabel2)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(a, javax.swing.GroupLayout.PREFERRED_SIZE, javax.s
wing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jLabel4)
.addComponent(resul))
.addGap(3, 3, 3)
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(b, javax.swing.GroupLayout.PREFERRED_SIZE, javax.s
wing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(44, 44, 44)
.addComponent(error)
.addContainerGap(60, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void bActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

int uno=0,dos=0, result;

try{


uno = Integer.parseInt(this.a.getText());
dos = Integer.parseInt(this.b.getText());
result = uno+dos;
resul.setText(String.valueOf(result));
}
catch (Exception e){
error.setText("ERROR!.. verifique que ingreso los 2 valores");
}


}
/**
* @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 cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(InterSuma.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(InterSuma.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(InterSuma.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(InterSuma.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new InterSuma().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField a;
private javax.swing.JTextField b;
private javax.swing.JLabel error;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel resul;
// End of variables declaration
}

También podría gustarte