Membuat DatePicker Atau Kalender Pada Java Netbeans

Membuat DatePicker Atau Kalender Pada Java Netbeans

https://2.bp.blogspot.com/-NOiODKq-O7w/V4ZEeadHYSI/AAAAAAAAC8Y/AH19xWgXRN8YccnrN7_v0nZMOLvSavY_gCLcB/s1600/Program-Cara-Membuat-DatePicker.jpg 

 

Pada kesempatan kali ini pembahasan mengenai pembuatan Kalender atau DatePicker. Kalender atau DatePicker merupakan komponen untuk entry data tanggal pada suatu database. Saat input tanggal, pengguna tidak perlu melakukan input data secara manual namun langsung saja memilih tanggal yang tampil kalender. Untuk pembuatan DatePicker pada Java Netbeans cukup mudah, Anda hanya perlu mendownload file DatePicker Di Sini terlebih dahulu. Berikut ini cara pembuatan DatePicker pada Java Netbeans:

1. Buatlah project baru
Anda perlu membuat membuka software Java Netbeans dan buat project baru dengan memilih File > New Project untuk membuat sebuah project baru.

https://2.bp.blogspot.com/-CgERQ5a6C7w/V4ZEfS1oImI/AAAAAAAAC8c/jBhsr_jxEnoCxR0ejigzbGKPGJmozmkoQCLcB/s1600/Project-Cara-membuat-DatePicker.jpg

Buat class baru dengan cara klik kanan pada package > New > Java class dan buat dengan nama CaraMembuatDatePicker.

https://3.bp.blogspot.com/-b4SLNkoj9ak/V4ZEjeVnYKI/AAAAAAAAC8k/xIVNkT8q2gARubG5lPfTwI9ZwblDuxu5wCLcB/s1600/Hasil%2BClass-Cara-Membuat-DatePicker.jpg

Buat script pemrograman java pada class CaraMembuatDatePicker.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cara.membuat.date.picker;

/**
*
* @author Ardy Sendleep
*/
public class CaraMembuatDatePicker {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Frame_date_picker Laund = new Frame_date_picker();
Laund.setVisible(true);
}
}

Buat frame baru dengan cara klik kanan pada package > New > JFrame Form dengan nama Frame_date_picker.

https://1.bp.blogspot.com/-xBHAi23k4YU/V4ZEllVsPaI/AAAAAAAAC8o/d7CHPNG3KeIumZTV-VX4rf8P7iuJR2PbgCLcB/s1600/Hasil%2BFrame-Cara-Membuat-DatePicker.jpg

Tambahkan Jcalendar yang telah didownload dengan cara klik kanan pada Palette > PaletteManager > Add from JAR > Pilih file > Pilih semua komponen > Swing Controls > Pilih JDateChooser untuk menggunakan DatePicker.

https://2.bp.blogspot.com/-M1LO83Q3sb8/V4ZErizFSZI/AAAAAAAAC8w/QCZCFleECosHftrJPaLI2SFlK34wfdapgCLcB/s1600/Mengatur-DatePicker2.jpg

https://2.bp.blogspot.com/-txyhWkIL2sg/V4ZEr4YGi6I/AAAAAAAAC80/4AWNW1Bd4eUo3jLh9YKqaCP1c_Pe81XWgCLcB/s1600/Mengatur-DatePicker.jpg

Buat desain frame seperti contoh dibawah ini.

https://1.bp.blogspot.com/-GGynX_GFb40/V4ZEo02cb4I/AAAAAAAAC8s/NTfLRqeGcEg19vvfHkb5N5D5OqO9Tv00wCLcB/s1600/Cara-Membuat-DatePicker.jpg

Buat script pada desain frame dengan cara klik kanan pada button Lihat > Events > Actions > ActionPerformed dan buat script pada frame.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cara.membuat.date.picker;

import java.text.SimpleDateFormat;

/**
*
* @author Ardy Sendleep
*/
public class Frame_date_picker extends javax.swing.JFrame {

/**
* Creates new form Frame_date_picker
*/
public Frame_date_picker() {
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();
btnLihat = new javax.swing.JButton();
txtHasil = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jDateChooser1 = new com.toedter.calendar.JDateChooser();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font(“Tahoma”, 1, 18)); // NOI18N
jLabel1.setText(“Cara Membuat Date Picker”);

jLabel2.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N
jLabel2.setText(“Kalender”);

btnLihat.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N
btnLihat.setText(“Lihat”);
btnLihat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLihatActionPerformed(evt);
}
});

txtHasil.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N

jLabel3.setFont(new java.awt.Font(“Tahoma”, 1, 14)); // NOI18N
jLabel3.setText(“Hasil”);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(58, 58, 58)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnLihat)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGap(54, 54, 54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtHasil)
.addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE))))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(jLabel1)
.addGap(48, 48, 48)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addComponent(btnLihat)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtHasil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addContainerGap(51, Short.MAX_VALUE))
);

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

private void btnLihatActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
SimpleDateFormat date;
date= new SimpleDateFormat(“MM-dd-yyy”);
txtHasil.setText(date.format(jDateChooser1.getDate()));
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“Nimbus”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Frame_date_picker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Frame_date_picker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Frame_date_picker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Frame_date_picker.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new Frame_date_picker().setVisible(true);
}
});
}
// Variables declaration – do not modify
private javax.swing.JButton btnLihat;
private com.toedter.calendar.JDateChooser jDateChooser1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField txtHasil;
// End of variables declaration
}

2. Hasil program 
Pada program DatePicker, Anda diminta untuk memilih tanggal, bulan, tahun pada kalender yang muncul pada JDateChooser kemudian pilih lihat maka akan muncul hasil tanggal, bulan dan tahun.

https://1.bp.blogspot.com/-tpyXkiLWHmQ/V4ZEgrFtjBI/AAAAAAAAC8g/E2hnIHOrQL46MuaeDe8A-qt0JNiibGtCACLcB/s1600/Gambar%2BProgram-Cara-Membuat-DatePicker.jpg

Download file program secara lengkap di sini: Download. 

 

Leave a Reply

Your email address will not be published. Required fields are marked *