0% found this document useful (0 votes)
60 views

Modul 5:: Write Once, Run Everywhere Rahmadi, S.E, S.Kom - 1

The document describes the objectives and coding for a Java program interface and controls format. It includes: 1. Designing the interface with labels and text fields for transaction date, type, account number, beginning balance, amount, and ending balance. 2. The coding implements the interface components with formatting, event handling, and calculations for the transaction fields.

Uploaded by

Rizka Ardina
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Modul 5:: Write Once, Run Everywhere Rahmadi, S.E, S.Kom - 1

The document describes the objectives and coding for a Java program interface and controls format. It includes: 1. Designing the interface with labels and text fields for transaction date, type, account number, beginning balance, amount, and ending balance. 2. The coding implements the interface components with formatting, event handling, and calculations for the transaction fields.

Uploaded by

Rizka Ardina
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

Modul 5:

Tujuan : Format Tampilan dan Kontrol.

1.Desain Interface :

2.Coding :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* java_format.java
*
* Created on Jun 20, 2009, 10:26:37 AM
*/

/**
*
* @author Acer
*/
import java.awt.Dimension;
Write Once, Run Everywhere
Rahmadi, S.E, S.Kom
Page |1
import java.awt.Point;
import java.awt.Toolkit;
//import tanggal dan waktu
import java.util.Date;
import java.text.SimpleDateFormat;
//message box
import javax.swing.JOptionPane;
public class java_format extends javax.swing.JFrame {
//deklerasi variabel
Date tanggal;
double saldo_awal;
double jumlah;
double saldo_akhir;
/** Creates new form java_format */
public java_format() {
initComponents();
//inialisasi varibael
tanggal = new Date();
saldo_awal=0;
jumlah=0;
saldo_akhir=0;
}

/** 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() {

jLabel8 = new javax.swing.JLabel();


jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jchk_setoran = new javax.swing.JCheckBox();
jchk_tarikan = new javax.swing.JCheckBox();
jformat_no_rekening = new javax.swing.JFormattedTextField();

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |2
jformat_saldo_awal = new javax.swing.JFormattedTextField();
jformat_jumlah = new javax.swing.JFormattedTextField();
jformat_saldo_akhir = new javax.swing.JFormattedTextField();
jtxt_tanggal = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jbtn_baru = new javax.swing.JButton();

jLabel8.setText("jLabel8");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Form Simpanan");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});

jLabel1.setFont(new java.awt.Font("Arial Black", 3, 36));


jLabel1.setText("Transaksi Simpanan");

jPanel1.setBackground(new java.awt.Color(51, 255, 255));

jLabel2.setText("Tanggal Transaksi");

jLabel3.setText("Jenis Transaksi");

jLabel4.setText("No. Rekening");

jLabel5.setText("Saldo Awal Simpanan");

jLabel6.setText("Jumlah Simpanan");

jLabel7.setText("Saldo Akhir Simpanan");

jchk_setoran.setText("Setoran");
jchk_setoran.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jchk_setoranActionPerformed(evt);
}
});

jchk_tarikan.setText("Tarikan");
jchk_tarikan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |3
jchk_tarikanActionPerformed(evt);
}
});

try {
jformat_no_rekening.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new
javax.swing.text.MaskFormatter("###-####-####")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
jformat_no_rekening.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jformat_no_rekeningActionPerformed(evt);
}
});
jformat_no_rekening.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jformat_no_rekeningFocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
jformat_no_rekeningFocusLost(evt);
}
});
jformat_no_rekening.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jformat_no_rekeningKeyPressed(evt);
}
});

jformat_saldo_awal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new
javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###,###,###.00"))));
jformat_saldo_awal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jformat_saldo_awalActionPerformed(evt);
}
});
jformat_saldo_awal.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jformat_saldo_awalFocusGained(evt);
}
});

jformat_jumlah.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new
javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###,###,###.00"))));

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |4
jformat_jumlah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jformat_jumlahActionPerformed(evt);
}
});
jformat_jumlah.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jformat_jumlahFocusLost(evt);
}
});
jformat_jumlah.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jformat_jumlahKeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
jformat_jumlahKeyReleased(evt);
}
});

jformat_saldo_akhir.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new
javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###,###,###.00"))));
jformat_saldo_akhir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jformat_saldo_akhirActionPerformed(evt);
}
});
jformat_saldo_akhir.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
jformat_saldo_akhirFocusGained(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);


jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(33, 33, 33)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5)

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |5
.addComponent(jLabel6)
.addComponent(jLabel7))
.addGap(64, 64, 64)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jchk_setoran)
.addGap(18, 18, 18)
.addComponent(jchk_tarikan))
.addComponent(jformat_no_rekening)
.addComponent(jformat_saldo_awal)
.addComponent(jformat_jumlah)
.addComponent(jformat_saldo_akhir, javax.swing.GroupLayout.DEFAULT_SIZE, 108,
Short.MAX_VALUE)
.addComponent(jtxt_tanggal, javax.swing.GroupLayout.PREFERRED_SIZE, 113,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(111, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(28, 28, 28)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jtxt_tanggal, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jchk_setoran)
.addComponent(jchk_tarikan))
.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jformat_no_rekening, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |6
.addComponent(jformat_saldo_awal, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jformat_jumlah, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jformat_saldo_akhir, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(39, Short.MAX_VALUE))
);

jButton1.setText("Tutup");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jbtn_baru.setText("Transaksi Baru");
jbtn_baru.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtn_baruActionPerformed(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()
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jbtn_baru)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1))

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |7
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(26, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jbtn_baru))
.addContainerGap(30, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void formWindowActivated(java.awt.event.WindowEvent evt) {


// TODO add your handling code here:
//form center
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation(new Point((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2));
//non aktif
jtxt_tanggal.setEditable(!true);
jchk_setoran.setEnabled(!true);
jchk_tarikan.setEnabled(!true);
jformat_no_rekening.setEditable(!true);
jformat_saldo_awal.setEditable(!true);
jformat_jumlah.setEditable(!true);
jformat_saldo_akhir.setEditable(!true);
}

private void jformat_saldo_awalActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jformat_saldo_awalFocusGained(java.awt.event.FocusEvent evt) {

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |8
// TODO add your handling code here:
jformat_saldo_awal.setHorizontalAlignment(jformat_saldo_awal.RIGHT);
// yourField.setHorizontalAlignment(align);
jformat_jumlah.grabFocus();
}

private void jformat_no_rekeningFocusLost(java.awt.event.FocusEvent evt) {


// TODO add your handling code here:
//saldo awal
saldo_awal=1000000000;
jformat_saldo_awal.setText(String.valueOf(saldo_awal));
jformat_saldo_awal.grabFocus();
}

private void jformat_no_rekeningActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:

private void jformat_no_rekeningKeyPressed(java.awt.event.KeyEvent evt) {


// TODO add your handling code here:

private void jformat_no_rekeningFocusGained(java.awt.event.FocusEvent evt) {


// TODO add your handling code here:

private void jformat_jumlahKeyPressed(java.awt.event.KeyEvent evt) {


// TODO add your handling code here:

private void jformat_jumlahActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jformat_jumlahKeyReleased(java.awt.event.KeyEvent evt) {


// TODO add your handling code here:

private void jformat_jumlahFocusLost(java.awt.event.FocusEvent evt) {

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
Page |9
// TODO add your handling code here:
//kontrol isi tidak boleh kosong
if (jformat_jumlah.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"Jumlah Tidak Boleh Kosong");
jbtn_baru.grabFocus();
}
else
{
jumlah=Double.valueOf(jformat_jumlah.getText());
jformat_jumlah.setHorizontalAlignment(jformat_jumlah.RIGHT);
if(jchk_setoran.isSelected()==true){
saldo_akhir=saldo_awal+jumlah;}
if(jchk_tarikan.isSelected()==true){
saldo_akhir=saldo_awal-jumlah;}
jformat_saldo_akhir.setText(String.valueOf(saldo_akhir));
jformat_saldo_akhir.grabFocus();
}
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
setVisible(false);
dispose();
}

private void jbtn_baruActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
//aktif
jtxt_tanggal.setEditable(!true);
jchk_setoran.setEnabled(true);
jchk_tarikan.setEnabled(true);
jformat_no_rekening.setEditable(true);
jformat_saldo_awal.setEditable(true);
jformat_jumlah.setEditable(true);
jformat_saldo_akhir.setEditable(true);
//inialisasi
SimpleDateFormat format_tanggal;
format_tanggal = new SimpleDateFormat("dd-MMMM-yyyy");
jtxt_tanggal.setText(format_tanggal.format(tanggal));
jchk_setoran.setSelected(false);
jchk_tarikan.setSelected(false);
jformat_no_rekening.setText("");
jformat_saldo_awal.setText("");

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
P a g e | 10
jformat_jumlah.setText("");
jformat_saldo_akhir.setText("");
jtxt_tanggal.grabFocus();
}

private void jformat_saldo_akhirFocusGained(java.awt.event.FocusEvent evt) {


// TODO add your handling code here:
jformat_saldo_akhir.setHorizontalAlignment(jformat_saldo_akhir.RIGHT);
//non aktif
jtxt_tanggal.setEditable(!true);
jchk_setoran.setEnabled(!true);
jchk_tarikan.setEnabled(!true);
jformat_no_rekening.setEditable(!true);
jformat_saldo_awal.setEditable(!true);
jformat_jumlah.setEditable(!true);
jformat_saldo_akhir.setEditable(!true);
jbtn_baru.grabFocus();

private void jformat_saldo_akhirActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
}

private void jchk_setoranActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
if(jchk_setoran.isSelected()==true){
jchk_tarikan.setSelected(false);
}
}

private void jchk_tarikanActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
if(jchk_tarikan.isSelected()==true){
jchk_setoran.setSelected(false);
}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
P a g e | 11
new java_format().setVisible(true);
}
});
}

// Variables declaration - do not modify


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 jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton jbtn_baru;
private javax.swing.JCheckBox jchk_setoran;
private javax.swing.JCheckBox jchk_tarikan;
private javax.swing.JFormattedTextField jformat_jumlah;
private javax.swing.JFormattedTextField jformat_no_rekening;
private javax.swing.JFormattedTextField jformat_saldo_akhir;
private javax.swing.JFormattedTextField jformat_saldo_awal;
private javax.swing.JTextField jtxt_tanggal;
// End of variables declaration

3.Implementation :

Write Once, Run Everywhere


Rahmadi, S.E, S.Kom
P a g e | 12
Write Once, Run Everywhere
Rahmadi, S.E, S.Kom
P a g e | 13

You might also like