Senin, 03 Januari 2011

Menciptakan Aplikasi Hitungan Uang

Pada kesempatan kali ini saya akan menjelaskan tentang cara pembuatan aplikasi hitungan yang sangat sederhana yaitu aplikasi yang saya buat adalah APLIKASI MENGHITUNG SISA UANG MAKAN SEHARI-HARI. Saya menggunakan bahasa java dalam pemrograman aplikasi ini,,
langsung saya jelaskan cara pembuatan aplikasi ini dengan cara yang sangat simple dan sederhana,,,
gunakan netbeans untuk membuat aplikasi ini,,
Buka netbeans lalu buat project baru,,,
buat jfrom frame baru,,, beri nama duit_saya.. atau apa terserah anda..
lalu buat desain programnya,, seperti di bawah ini,,
setelah itu,,,, klik 2X pada tombol hitung dan masukan kode berikut:
package uangsaya;
import javax.swing.JOptionPane;
/**
*
* @author burhan
*/
public class duit_saya extends javax.swing.JFrame {
/** Creates new form duit_saya */
public duit_saya() {
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();
jLabel4 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
sasaa = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“Sisa Uang jajan”);
setAlwaysOnTop(true);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setFont(new java.awt.Font(“Bitstream Charter”, 1, 14)); // NOI18N
setLocationByPlatform(true);
jLabel1.setText(“Pemasukan”);
jLabel2.setText(“Pengeluaran”);
jLabel4.setText(“Sisa Uang”);
jTextField2.setAutoscrolls(true);
jTextField2.setDoubleBuffered(true);
jTextField2.setDragEnabled(true);
jTextField2.setFocusCycleRoot(true);
jTextField2.setFocusTraversalPolicyProvider(true);
jTextField2.setInheritsPopupMenu(true);
jButton1.setText(“Hitung”);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText(“Batal”);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
.addGap(35, 35, 35))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
.addGap(51, 51, 51)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sasaa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
.addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(sasaa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
getAccessibleContext().setAccessibleName(“Sisa Uang Makan”);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-393)/2, (screenSize.height-213)/2, 393, 213);
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int pemasukan= Integer.parseInt(jTextField1.getText());
int pengeluaran=Integer.parseInt(jTextField2.getText());
int sisa=pemasukan-pengeluaran;
String a=String.valueOf(sisa);
sasaa.setText(a);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int keluar;
keluar=JOptionPane.showConfirmDialog(null, “Anda yakin mau keluar dari area ini”,”warning”,JOptionPane.YES_NO_OPTION);
if (keluar==JOptionPane.YES_OPTION){
System.exit(0);
}
else
{
return;}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new duit_saya().setVisible(true);
}
});
}
// Variables declaration – do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField sasaa;
// End of variables declaration
}
kode terse4but sudah termasuk event dari tombol Batal..
seperti ini tampilan saat membuat source untuk event aplikasi
jika semua sudah selesai,, lalu RUN dan lihat hasilnya,,,
jika anda berhasil maka akan tampil sebuah aplikasi seperti ini;
maka kita tinggal memasukan data-data yang kita perlukan dan kita bisa dengan mudah menghitung sisa pengeluaran uang jajan kita,,
Jika teman-teman masih adaang belum faham, silahka komentari artikel saya ini, semoga bermanfaat :D   :D   :D

Tidak ada komentar:

Posting Komentar