Membuat Kalkulator Sederhana
4 posters
U3Dcrew :: Programming :: Java
Page 1 of 1
Membuat Kalkulator Sederhana
Disini saya memakai Netbeans untuk membuat aplikasi sederhana ini, dimana komponen utama yang dibutuhkan adalah 1 button, 4 radio button, 3 text field.
Download here http://www.fairfaxtmjdentist.com/Latihan1.rar
- Spoiler:
- /*
* Tampilan1.java
*
* Created on 09 Mar 10, 15:21:05
*/
/**
*
* @author r3m1ck rahm4n1
*/
public class Tampilan1 extends javax.swing.JFrame {
/** Creates new form Tampilan1 */
public Tampilan1() {
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() {
jPanel1 = new javax.swing.JPanel();
btnProses = new javax.swing.JButton();
txtAngka1 = new javax.swing.JTextField();
txtAngka2 = new javax.swing.JTextField();
txtHasil = new javax.swing.JTextField();
rdoTambah = new javax.swing.JRadioButton();
rdoKurang = new javax.swing.JRadioButton();
rdoKali = new javax.swing.JRadioButton();
rdoBagi = new javax.swing.JRadioButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnProses.setText("Hitung");
btnProses.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnProsesActionPerformed(evt);
}
});
txtAngka1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtAngka1ActionPerformed(evt);
}
});
rdoTambah.setText("tambah ( + )");
rdoKurang.setText("kurang ( - )");
rdoKali.setText("kali ( * )");
rdoBagi.setText("bagi ( / )");
jLabel1.setText("OPERASI");
jLabel2.setText("ANGKA 1");
jLabel3.setText("ANGKA 2");
jLabel4.setText("KALKULATOR SEDERHANA");
jLabel5.setText("r3m1ck - indonesiancoder");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(53, 53, 53)
.addComponent(jLabel1)
.addGap(41, 41, 41)
.addComponent(jLabel3))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(txtAngka1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(rdoKurang)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(rdoTambah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtAngka2, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(rdoKali)
.addComponent(rdoBagi))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(8, 8,
.addComponent(btnProses)
.addGap(18, 18, 18)
.addComponent(txtHasil, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(76, 76, 76)
.addComponent(jLabel4)))
.addContainerGap(40, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(157, Short.MAX_VALUE)
.addComponent(jLabel5)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel4)
.addGap(22, 22, 22)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtAngka1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtAngka2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rdoTambah))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rdoKurang)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rdoKali)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rdoBagi)
.addGap(31, 31, 31)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnProses)
.addComponent(txtHasil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
.addComponent(jLabel5))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void txtAngka1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnProsesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int bil1 = Integer.parseInt(txtAngka1.getText());
int bil2 = Integer.parseInt(txtAngka2.getText());
float hasil = 0;
if (rdoTambah.isSelected()==true) {
hasil = (float) bil1+bil2;
} else if (rdoKurang.isSelected()==true) {
hasil = (float) bil1-bil2;
} else if (rdoKali.isSelected()==true) {
hasil = (float) bil1*bil2;
} else if (rdoBagi.isSelected()==true) {
hasil = (float) bil1/bil2;
}
String hasil2 = String.valueOf(hasil);
txtHasil.setText(hasil2);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Tampilan1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnProses;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButton rdoBagi;
private javax.swing.JRadioButton rdoKali;
private javax.swing.JRadioButton rdoKurang;
private javax.swing.JRadioButton rdoTambah;
private javax.swing.JTextField txtAngka1;
private javax.swing.JTextField txtAngka2;
private javax.swing.JTextField txtHasil;
// End of variables declaration
}
- Spoiler:
Download here http://www.fairfaxtmjdentist.com/Latihan1.rar
Re: Membuat Kalkulator Sederhana
INJIN sedot master.....
bl4ck f4d3- junior
- Posts : 4
Reputation : 0
Join date : 2010-03-08
U3Dcrew :: Programming :: Java
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum