Membuat Kalkulator Sederhana

View previous topic View next topic Go down

Membuat Kalkulator Sederhana

Post by r3m1ck on Wed Mar 24, 2010 7:52 am

Disini saya memakai Netbeans untuk membuat aplikasi sederhana ini, dimana komponen utama yang dibutuhkan adalah 1 button, 4 radio button, 3 text field.


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, Cool
.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

_________________
--==[ Nothing secure....Nothing is impossible ]==--

r3m1ck
Founder u3d
Founder u3d

Posts : 111
Reputation : -1
Join date : 2010-03-06
Location : r00t

View user profile http://r3m1ck.uni.cc/

Back to top Go down

Re: Membuat Kalkulator Sederhana

Post by bl4ck f4d3 on Wed Mar 24, 2010 8:09 am

INJIN sedot master.....

bl4ck f4d3
junior
junior

Posts : 4
Reputation : 0
Join date : 2010-03-08

View user profile

Back to top Go down

Re: Membuat Kalkulator Sederhana

Post by r3m1ck on Wed Mar 24, 2010 12:33 pm

monggoh om capung gondrong

_________________
--==[ Nothing secure....Nothing is impossible ]==--

r3m1ck
Founder u3d
Founder u3d

Posts : 111
Reputation : -1
Join date : 2010-03-06
Location : r00t

View user profile http://r3m1ck.uni.cc/

Back to top Go down

Re: Membuat Kalkulator Sederhana

Post by banditc0de on Sat Mar 27, 2010 1:17 am

belajar java ah!! hehe..

banditc0de
V.I.P Member
V.I.P Member

Posts : 19
Reputation : 0
Join date : 2010-03-26
Age : 26
Location : ../../../../

View user profile http://vir0e5.blogspot.com

Back to top Go down

Re: Membuat Kalkulator Sederhana

Post by r3m1ck on Sat Mar 27, 2010 4:55 pm

Wiw ... om kan uda jago java,, ane yg diajarin y kk... :apn:

_________________
--==[ Nothing secure....Nothing is impossible ]==--

r3m1ck
Founder u3d
Founder u3d

Posts : 111
Reputation : -1
Join date : 2010-03-06
Location : r00t

View user profile http://r3m1ck.uni.cc/

Back to top Go down

Re: Membuat Kalkulator Sederhana

Post by otong on Sat Mar 27, 2010 8:15 pm

weh... keluar deh programer kita.. wkwkwkkw

_________________
visit me in http://otong.info

otong
info|otong
info|otong

Posts : 81
Reputation : 0
Join date : 2010-03-06
Location : Sleman Sembada

View user profile http://otong.info

Back to top Go down

Re: Membuat Kalkulator Sederhana

Post by Sponsored content Today at 5:10 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum