penjumlahan

download penjumlahan

If you can't read please download the document

description

code java

Transcript of penjumlahan

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author win7 */ public class Penjumlahan extends javax.swing.JFrame { private String str = "Hasilnya adalah : "; private double a, b; /** * Creates new form Penjumlahan */ public Penjumlahan() { 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") // private void initComponents() { jLabel_Ket = new javax.swing.JLabel(); txtA = new javax.swing.JTextField(); jLabel_plus = new javax.swing.JLabel(); txtB = new javax.swing.JTextField(); jButton_Hit = new javax.swing.JButton(); jLabel_Hasil = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel_Ket.setText("Penjumlahan integer :"); txtA.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txtAActionPerformed(evt); } }); jLabel_plus.setText("+"); jButton_Hit.setText("Hitung"); jButton_Hit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton_HitActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP ane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel_Ket) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(txtA, javax.swing.GroupLayout.PREFERRED_SI ZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(jLabel_plus) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(txtB, javax.swing.GroupLayout.PREFERRED_SI ZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jButton_Hit)) .addGroup(layout.createSequentialGroup() .addGap(84, 84, 84) .addComponent(jLabel_Hasil, javax.swing.GroupLayout.PREF ERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(67, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING ) .addGroup(layout.createSequentialGroup() .addGap(63, 63, 63) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali gnment.BASELINE) .addComponent(jLabel_Ket, javax.swing.GroupLayout.PREFERRED_ SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtA, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel_plus, javax.swing.GroupLayout.PREFERRED _SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtB, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton_Hit)) .addGap(36, 36, 36) .addComponent(jLabel_Hasil, javax.swing.GroupLayout.PREFERRED_SI ZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(145, Short.MAX_VALUE)) ); pack(); }// private void txtAActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton_HitActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:a = Double.parseDouble(txtA.getText()); b = Double.parseDouble(txtB.getText()); double hasil = a + b; jLabel_Hasil.setText(str + hasil); } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* 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(Penjumlahan.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Penjumlahan.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Penjumlahan.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Penjumlahan.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Penjumlahan().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton_Hit; private javax.swing.JLabel jLabel_Hasil; private javax.swing.JLabel jLabel_Ket; private javax.swing.JLabel jLabel_plus; private javax.swing.JTextField txtA; private javax.swing.JTextField txtB; // End of variables declaration }