1. Desekripsi
Aplikasi Tiket Bus
Aplikasi ini dibuat untuk memudahkan Pengguna ketika ingin mengetahui harga Tiket Bus sebelum memesan sehingga bisa mempersiapkan uang pas. Program ini cukup sederhana, Pengguna Tinggal pilih Rute Bus yang di tuju lalu akan muncul harga tiket satuan jikalau pengguna ingin membeli tiket lebih dari satu, pengguna tinggal menggunakan item Combobox yang berisi 1-4 lalu akan muncul harga total setelah itu centang kotak checkbox untuk mendapatkan diskon8% kemudian pengguna tekan tombol bayar untuk mengetahui harga yang harus dibayar, Setelah Pengguna selesai menjalankan aplikasi, data akan tersimpan kedalam database. didalam aplikasi ini juga terdapat item - item sebagai berikut :
8 label
2 Combo Box
4 TextField
1 checkBox
5 Button
2. Flowchart
3. Desain Database/Struktur Tabel
4. ScreenShoot
Screenshoot Design
Screenshoot Source
5. Source Code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package programbus;
import java.awt.EventQueue;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.RollbackException;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author acer
*/
public class Bus extends JPanel {
public Bus() {
initComponents();
if (!Beans.isDesignTime()) {
entityManager.getTransaction().begin();
}
}
/**
* 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() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("programbus?zeroDateTimeBehavior=convertToNullPU").createEntityManager();
query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT h FROM Hargatiketbus h");
list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
BGTujuan = new javax.swing.ButtonGroup();
masterScrollPane = new javax.swing.JScrollPane();
masterTable = new javax.swing.JTable();
idLabel = new javax.swing.JLabel();
namaLabel = new javax.swing.JLabel();
tujuanLabel = new javax.swing.JLabel();
hargaLabel = new javax.swing.JLabel();
jumlahLabel = new javax.swing.JLabel();
hargaTotalLabel = new javax.swing.JLabel();
hargaBayarLabel = new javax.swing.JLabel();
idField = new javax.swing.JTextField();
namaField = new javax.swing.JTextField();
TxtHarga = new javax.swing.JTextField();
TxtTotal = new javax.swing.JTextField();
TxtDiskon = new javax.swing.JTextField();
TxtBayar = new javax.swing.JTextField();
saveButton = new javax.swing.JButton();
refreshButton = new javax.swing.JButton();
newButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
CmbTujuan = new javax.swing.JComboBox<>();
CmbJum = new javax.swing.JComboBox<>();
ChkDiskon = new javax.swing.JCheckBox();
BtBayar = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
FormListener formListener = new FormListener();
masterTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
columnBinding.setColumnName("Id");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nama}"));
columnBinding.setColumnName("Nama");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tujuan}"));
columnBinding.setColumnName("Tujuan");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${harga}"));
columnBinding.setColumnName("Harga");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${jumlah}"));
columnBinding.setColumnName("Jumlah");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${hargaTotal}"));
columnBinding.setColumnName("Harga Total");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${diskon}"));
columnBinding.setColumnName("Diskon");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${hargaBayar}"));
columnBinding.setColumnName("Harga Bayar");
columnBinding.setColumnClass(Integer.class);
bindingGroup.addBinding(jTableBinding);
masterScrollPane.setViewportView(masterTable);
idLabel.setText("Id:");
namaLabel.setText("Nama:");
tujuanLabel.setText("Tujuan:");
hargaLabel.setText("Harga:");
jumlahLabel.setText("Jumlah:");
hargaTotalLabel.setText("Harga Total:");
hargaBayarLabel.setText("Harga Bayar:");
org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), idField, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), idField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.nama}"), namaField, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), namaField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.harga}"), TxtHarga, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtHarga, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
TxtHarga.addActionListener(formListener);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.hargaTotal}"), TxtTotal, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtTotal, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.diskon}"), TxtDiskon, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtDiskon, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.hargaBayar}"), TxtBayar, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtBayar, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
saveButton.setText("Save");
saveButton.addActionListener(formListener);
refreshButton.setText("Refresh");
refreshButton.addActionListener(formListener);
newButton.setText("New");
newButton.addActionListener(formListener);
deleteButton.setText("Delete");
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
deleteButton.addActionListener(formListener);
CmbTujuan.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Tangerang-Jakarta", "Tangerang-Serang", "Tangerang-Bandung", "Tangerang-Lampung" }));
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.tujuan}"), CmbTujuan, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
bindingGroup.addBinding(binding);
CmbTujuan.addActionListener(formListener);
CmbJum.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " " }));
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.jumlah}"), CmbJum, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
bindingGroup.addBinding(binding);
CmbJum.addActionListener(formListener);
ChkDiskon.setText("Diskon 8%");
ChkDiskon.addActionListener(formListener);
BtBayar.setText("Bayar");
BtBayar.addActionListener(formListener);
jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(153, 0, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Pembelian Tiket Bus Tangerang Abadi");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(masterScrollPane)
.addGroup(layout.createSequentialGroup()
.addGap(0, 169, Short.MAX_VALUE)
.addComponent(BtBayar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(107, 107, 107)
.addComponent(newButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(deleteButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(refreshButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveButton))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(idLabel)
.addComponent(namaLabel)
.addComponent(tujuanLabel)
.addComponent(hargaLabel)
.addComponent(jumlahLabel)
.addComponent(hargaTotalLabel)
.addComponent(hargaBayarLabel))
.addGap(21, 21, 21))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(ChkDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(idField)
.addComponent(namaField)
.addComponent(TxtHarga)
.addComponent(TxtTotal)
.addComponent(TxtDiskon)
.addComponent(TxtBayar)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(CmbTujuan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CmbJum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE)))))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 426, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(163, 163, 163))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deleteButton, newButton, refreshButton, saveButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(19, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(33, 33, 33)
.addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(idLabel)
.addComponent(idField, 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(namaLabel)
.addComponent(namaField, 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(tujuanLabel)
.addComponent(CmbTujuan, 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(hargaLabel)
.addComponent(TxtHarga, 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(jumlahLabel)
.addComponent(CmbJum, 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(hargaTotalLabel)
.addComponent(TxtTotal, 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(TxtDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ChkDiskon))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hargaBayarLabel)
.addComponent(TxtBayar, 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(saveButton)
.addComponent(refreshButton)
.addComponent(deleteButton)
.addComponent(newButton)
.addComponent(BtBayar))
.addContainerGap())
);
bindingGroup.bind();
}
// Code for dispatching events from components to event handlers.
private class FormListener implements java.awt.event.ActionListener {
FormListener() {}
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource() == TxtHarga) {
Bus.this.TxtHargaActionPerformed(evt);
}
else if (evt.getSource() == saveButton) {
Bus.this.saveButtonActionPerformed(evt);
}
else if (evt.getSource() == refreshButton) {
Bus.this.refreshButtonActionPerformed(evt);
}
else if (evt.getSource() == newButton) {
Bus.this.newButtonActionPerformed(evt);
}
else if (evt.getSource() == deleteButton) {
Bus.this.deleteButtonActionPerformed(evt);
}
else if (evt.getSource() == CmbTujuan) {
Bus.this.CmbTujuanActionPerformed(evt);
}
else if (evt.getSource() == CmbJum) {
Bus.this.CmbJumActionPerformed(evt);
}
else if (evt.getSource() == ChkDiskon) {
Bus.this.ChkDiskonActionPerformed(evt);
}
else if (evt.getSource() == BtBayar) {
Bus.this.BtBayarActionPerformed(evt);
}
}
}// </editor-fold>
@SuppressWarnings("unchecked")
private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
entityManager.getTransaction().rollback();
entityManager.getTransaction().begin();
java.util.Collection data = query.getResultList();
for (Object entity : data) {
entityManager.refresh(entity);
}
list.clear();
list.addAll(data);
}
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
int[] selected = masterTable.getSelectedRows();
List<programbus.Hargatiketbus> toRemove = new ArrayList<programbus.Hargatiketbus>(selected.length);
for (int idx = 0; idx < selected.length; idx++) {
programbus.Hargatiketbus h = list.get(masterTable.convertRowIndexToModel(selected[idx]));
toRemove.add(h);
entityManager.remove(h);
}
list.removeAll(toRemove);
}
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {
programbus.Hargatiketbus h = new programbus.Hargatiketbus();
entityManager.persist(h);
list.add(h);
int row = list.size() - 1;
masterTable.setRowSelectionInterval(row, row);
masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
} catch (RollbackException rex) {
rex.printStackTrace();
entityManager.getTransaction().begin();
List<programbus.Hargatiketbus> merged = new ArrayList<programbus.Hargatiketbus>(list.size());
for (programbus.Hargatiketbus h : list) {
merged.add(entityManager.merge(h));
}
list.clear();
list.addAll(merged);
}
}
private void CmbTujuanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String tujuan = null;
if (CmbTujuan.getSelectedItem()== "Tangerang-Jakarta"){
TxtHarga.setText("35000");
}
else if (CmbTujuan.getSelectedItem()== "Tangerang-Serang"){
TxtHarga.setText("40000");
}
else if (CmbTujuan.getSelectedItem()== "Tangerang-Bandung"){
TxtHarga.setText("60000");
}
else if (CmbTujuan.getSelectedItem()== "Tangerang-Lampung"){
TxtHarga.setText("90000");
}
}
private void TxtHargaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void CmbJumActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
for(int i=1;i<5;i++){
CmbJum.addItem(""+i);
}
if (CmbJum.getSelectedItem().equals("1")){
TxtTotal.setText(TxtHarga.getText());
}
else if (CmbJum.getSelectedItem().equals("2")){
int harga = Integer.parseInt(TxtHarga.getText());
int total = harga*2 ;
TxtTotal.setText(Integer.toString(total));
}
else if (CmbJum.getSelectedItem().equals("3")){
int harga = Integer.parseInt(TxtHarga.getText());
int total = harga*3 ;
TxtTotal.setText(Integer.toString(total));
}
else if (CmbJum.getSelectedItem().equals("4")){
int harga = Integer.parseInt(TxtHarga.getText());
int total = harga*4 ;
TxtTotal.setText(Integer.toString(total));
}
}
private void ChkDiskonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (ChkDiskon.isSelected()){
int total = Integer.parseInt(TxtHarga.getText());
int diskon = total*8/100;
TxtDiskon.setText(Integer.toString(diskon));
}
}
private void BtBayarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//create variable
{
int angka1,angka2,hasil;
//input nilai
angka1 = Integer.parseInt(TxtTotal.getText());
angka2 = Integer.parseInt(TxtDiskon.getText());
//rumus
hasil = angka1 - angka2;
//output
TxtBayar.setText(Integer.toString(hasil));
}
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup BGTujuan;
private javax.swing.JButton BtBayar;
private javax.swing.JCheckBox ChkDiskon;
private javax.swing.JComboBox<String> CmbJum;
private javax.swing.JComboBox<String> CmbTujuan;
private javax.swing.JTextField TxtBayar;
private javax.swing.JTextField TxtDiskon;
private javax.swing.JTextField TxtHarga;
private javax.swing.JTextField TxtTotal;
private javax.swing.JButton deleteButton;
private javax.persistence.EntityManager entityManager;
private javax.swing.JLabel hargaBayarLabel;
private javax.swing.JLabel hargaLabel;
private javax.swing.JLabel hargaTotalLabel;
private javax.swing.JTextField idField;
private javax.swing.JLabel idLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jumlahLabel;
private java.util.List<programbus.Hargatiketbus> list;
private javax.swing.JScrollPane masterScrollPane;
private javax.swing.JTable masterTable;
private javax.swing.JTextField namaField;
private javax.swing.JLabel namaLabel;
private javax.swing.JButton newButton;
private javax.persistence.Query query;
private javax.swing.JButton refreshButton;
private javax.swing.JButton saveButton;
private javax.swing.JLabel tujuanLabel;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration
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(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
frame.setContentPane(new Bus());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
}
Aplikasi Tiket Bus
Aplikasi ini dibuat untuk memudahkan Pengguna ketika ingin mengetahui harga Tiket Bus sebelum memesan sehingga bisa mempersiapkan uang pas. Program ini cukup sederhana, Pengguna Tinggal pilih Rute Bus yang di tuju lalu akan muncul harga tiket satuan jikalau pengguna ingin membeli tiket lebih dari satu, pengguna tinggal menggunakan item Combobox yang berisi 1-4 lalu akan muncul harga total setelah itu centang kotak checkbox untuk mendapatkan diskon8% kemudian pengguna tekan tombol bayar untuk mengetahui harga yang harus dibayar, Setelah Pengguna selesai menjalankan aplikasi, data akan tersimpan kedalam database. didalam aplikasi ini juga terdapat item - item sebagai berikut :
8 label
2 Combo Box
4 TextField
1 checkBox
5 Button
2. Flowchart
3. Desain Database/Struktur Tabel
Screenshoot Design
Screenshoot Source
Screenshoot Running
5. Source Code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package programbus;
import java.awt.EventQueue;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.RollbackException;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author acer
*/
public class Bus extends JPanel {
public Bus() {
initComponents();
if (!Beans.isDesignTime()) {
entityManager.getTransaction().begin();
}
}
/**
* 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() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("programbus?zeroDateTimeBehavior=convertToNullPU").createEntityManager();
query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT h FROM Hargatiketbus h");
list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
BGTujuan = new javax.swing.ButtonGroup();
masterScrollPane = new javax.swing.JScrollPane();
masterTable = new javax.swing.JTable();
idLabel = new javax.swing.JLabel();
namaLabel = new javax.swing.JLabel();
tujuanLabel = new javax.swing.JLabel();
hargaLabel = new javax.swing.JLabel();
jumlahLabel = new javax.swing.JLabel();
hargaTotalLabel = new javax.swing.JLabel();
hargaBayarLabel = new javax.swing.JLabel();
idField = new javax.swing.JTextField();
namaField = new javax.swing.JTextField();
TxtHarga = new javax.swing.JTextField();
TxtTotal = new javax.swing.JTextField();
TxtDiskon = new javax.swing.JTextField();
TxtBayar = new javax.swing.JTextField();
saveButton = new javax.swing.JButton();
refreshButton = new javax.swing.JButton();
newButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
CmbTujuan = new javax.swing.JComboBox<>();
CmbJum = new javax.swing.JComboBox<>();
ChkDiskon = new javax.swing.JCheckBox();
BtBayar = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
FormListener formListener = new FormListener();
masterTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
columnBinding.setColumnName("Id");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nama}"));
columnBinding.setColumnName("Nama");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tujuan}"));
columnBinding.setColumnName("Tujuan");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${harga}"));
columnBinding.setColumnName("Harga");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${jumlah}"));
columnBinding.setColumnName("Jumlah");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${hargaTotal}"));
columnBinding.setColumnName("Harga Total");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${diskon}"));
columnBinding.setColumnName("Diskon");
columnBinding.setColumnClass(Integer.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${hargaBayar}"));
columnBinding.setColumnName("Harga Bayar");
columnBinding.setColumnClass(Integer.class);
bindingGroup.addBinding(jTableBinding);
masterScrollPane.setViewportView(masterTable);
idLabel.setText("Id:");
namaLabel.setText("Nama:");
tujuanLabel.setText("Tujuan:");
hargaLabel.setText("Harga:");
jumlahLabel.setText("Jumlah:");
hargaTotalLabel.setText("Harga Total:");
hargaBayarLabel.setText("Harga Bayar:");
org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), idField, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), idField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.nama}"), namaField, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), namaField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.harga}"), TxtHarga, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtHarga, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
TxtHarga.addActionListener(formListener);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.hargaTotal}"), TxtTotal, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtTotal, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.diskon}"), TxtDiskon, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtDiskon, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.hargaBayar}"), TxtBayar, org.jdesktop.beansbinding.BeanProperty.create("text"));
binding.setSourceUnreadableValue("null");
bindingGroup.addBinding(binding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), TxtBayar, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
saveButton.setText("Save");
saveButton.addActionListener(formListener);
refreshButton.setText("Refresh");
refreshButton.addActionListener(formListener);
newButton.setText("New");
newButton.addActionListener(formListener);
deleteButton.setText("Delete");
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
deleteButton.addActionListener(formListener);
CmbTujuan.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Tangerang-Jakarta", "Tangerang-Serang", "Tangerang-Bandung", "Tangerang-Lampung" }));
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.tujuan}"), CmbTujuan, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
bindingGroup.addBinding(binding);
CmbTujuan.addActionListener(formListener);
CmbJum.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { " " }));
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.jumlah}"), CmbJum, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
bindingGroup.addBinding(binding);
CmbJum.addActionListener(formListener);
ChkDiskon.setText("Diskon 8%");
ChkDiskon.addActionListener(formListener);
BtBayar.setText("Bayar");
BtBayar.addActionListener(formListener);
jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(153, 0, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Pembelian Tiket Bus Tangerang Abadi");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(masterScrollPane)
.addGroup(layout.createSequentialGroup()
.addGap(0, 169, Short.MAX_VALUE)
.addComponent(BtBayar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(107, 107, 107)
.addComponent(newButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(deleteButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(refreshButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(saveButton))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(idLabel)
.addComponent(namaLabel)
.addComponent(tujuanLabel)
.addComponent(hargaLabel)
.addComponent(jumlahLabel)
.addComponent(hargaTotalLabel)
.addComponent(hargaBayarLabel))
.addGap(21, 21, 21))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(ChkDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(idField)
.addComponent(namaField)
.addComponent(TxtHarga)
.addComponent(TxtTotal)
.addComponent(TxtDiskon)
.addComponent(TxtBayar)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(CmbTujuan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(CmbJum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE)))))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 426, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(163, 163, 163))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deleteButton, newButton, refreshButton, saveButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(19, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(33, 33, 33)
.addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(idLabel)
.addComponent(idField, 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(namaLabel)
.addComponent(namaField, 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(tujuanLabel)
.addComponent(CmbTujuan, 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(hargaLabel)
.addComponent(TxtHarga, 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(jumlahLabel)
.addComponent(CmbJum, 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(hargaTotalLabel)
.addComponent(TxtTotal, 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(TxtDiskon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ChkDiskon))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hargaBayarLabel)
.addComponent(TxtBayar, 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(saveButton)
.addComponent(refreshButton)
.addComponent(deleteButton)
.addComponent(newButton)
.addComponent(BtBayar))
.addContainerGap())
);
bindingGroup.bind();
}
// Code for dispatching events from components to event handlers.
private class FormListener implements java.awt.event.ActionListener {
FormListener() {}
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (evt.getSource() == TxtHarga) {
Bus.this.TxtHargaActionPerformed(evt);
}
else if (evt.getSource() == saveButton) {
Bus.this.saveButtonActionPerformed(evt);
}
else if (evt.getSource() == refreshButton) {
Bus.this.refreshButtonActionPerformed(evt);
}
else if (evt.getSource() == newButton) {
Bus.this.newButtonActionPerformed(evt);
}
else if (evt.getSource() == deleteButton) {
Bus.this.deleteButtonActionPerformed(evt);
}
else if (evt.getSource() == CmbTujuan) {
Bus.this.CmbTujuanActionPerformed(evt);
}
else if (evt.getSource() == CmbJum) {
Bus.this.CmbJumActionPerformed(evt);
}
else if (evt.getSource() == ChkDiskon) {
Bus.this.ChkDiskonActionPerformed(evt);
}
else if (evt.getSource() == BtBayar) {
Bus.this.BtBayarActionPerformed(evt);
}
}
}// </editor-fold>
@SuppressWarnings("unchecked")
private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
entityManager.getTransaction().rollback();
entityManager.getTransaction().begin();
java.util.Collection data = query.getResultList();
for (Object entity : data) {
entityManager.refresh(entity);
}
list.clear();
list.addAll(data);
}
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
int[] selected = masterTable.getSelectedRows();
List<programbus.Hargatiketbus> toRemove = new ArrayList<programbus.Hargatiketbus>(selected.length);
for (int idx = 0; idx < selected.length; idx++) {
programbus.Hargatiketbus h = list.get(masterTable.convertRowIndexToModel(selected[idx]));
toRemove.add(h);
entityManager.remove(h);
}
list.removeAll(toRemove);
}
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {
programbus.Hargatiketbus h = new programbus.Hargatiketbus();
entityManager.persist(h);
list.add(h);
int row = list.size() - 1;
masterTable.setRowSelectionInterval(row, row);
masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
} catch (RollbackException rex) {
rex.printStackTrace();
entityManager.getTransaction().begin();
List<programbus.Hargatiketbus> merged = new ArrayList<programbus.Hargatiketbus>(list.size());
for (programbus.Hargatiketbus h : list) {
merged.add(entityManager.merge(h));
}
list.clear();
list.addAll(merged);
}
}
private void CmbTujuanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String tujuan = null;
if (CmbTujuan.getSelectedItem()== "Tangerang-Jakarta"){
TxtHarga.setText("35000");
}
else if (CmbTujuan.getSelectedItem()== "Tangerang-Serang"){
TxtHarga.setText("40000");
}
else if (CmbTujuan.getSelectedItem()== "Tangerang-Bandung"){
TxtHarga.setText("60000");
}
else if (CmbTujuan.getSelectedItem()== "Tangerang-Lampung"){
TxtHarga.setText("90000");
}
}
private void TxtHargaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void CmbJumActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
for(int i=1;i<5;i++){
CmbJum.addItem(""+i);
}
if (CmbJum.getSelectedItem().equals("1")){
TxtTotal.setText(TxtHarga.getText());
}
else if (CmbJum.getSelectedItem().equals("2")){
int harga = Integer.parseInt(TxtHarga.getText());
int total = harga*2 ;
TxtTotal.setText(Integer.toString(total));
}
else if (CmbJum.getSelectedItem().equals("3")){
int harga = Integer.parseInt(TxtHarga.getText());
int total = harga*3 ;
TxtTotal.setText(Integer.toString(total));
}
else if (CmbJum.getSelectedItem().equals("4")){
int harga = Integer.parseInt(TxtHarga.getText());
int total = harga*4 ;
TxtTotal.setText(Integer.toString(total));
}
}
private void ChkDiskonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (ChkDiskon.isSelected()){
int total = Integer.parseInt(TxtHarga.getText());
int diskon = total*8/100;
TxtDiskon.setText(Integer.toString(diskon));
}
}
private void BtBayarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//create variable
{
int angka1,angka2,hasil;
//input nilai
angka1 = Integer.parseInt(TxtTotal.getText());
angka2 = Integer.parseInt(TxtDiskon.getText());
//rumus
hasil = angka1 - angka2;
//output
TxtBayar.setText(Integer.toString(hasil));
}
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup BGTujuan;
private javax.swing.JButton BtBayar;
private javax.swing.JCheckBox ChkDiskon;
private javax.swing.JComboBox<String> CmbJum;
private javax.swing.JComboBox<String> CmbTujuan;
private javax.swing.JTextField TxtBayar;
private javax.swing.JTextField TxtDiskon;
private javax.swing.JTextField TxtHarga;
private javax.swing.JTextField TxtTotal;
private javax.swing.JButton deleteButton;
private javax.persistence.EntityManager entityManager;
private javax.swing.JLabel hargaBayarLabel;
private javax.swing.JLabel hargaLabel;
private javax.swing.JLabel hargaTotalLabel;
private javax.swing.JTextField idField;
private javax.swing.JLabel idLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jumlahLabel;
private java.util.List<programbus.Hargatiketbus> list;
private javax.swing.JScrollPane masterScrollPane;
private javax.swing.JTable masterTable;
private javax.swing.JTextField namaField;
private javax.swing.JLabel namaLabel;
private javax.swing.JButton newButton;
private javax.persistence.Query query;
private javax.swing.JButton refreshButton;
private javax.swing.JButton saveButton;
private javax.swing.JLabel tujuanLabel;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration
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(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Bus.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
frame.setContentPane(new Bus());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
}
kodingan ini terhubung dengan stock gak ya? misal sisa stock tiket 4 kursi lagi
ReplyDeleteapa ada codingan lengkapnya semuaa?
ReplyDelete