Tiket Kreta Api
Latihan Pembuatan Project Tiket Kreta Api.
//Code Project
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DINDIN
*/
public class TiketKretaApi extends javax.swing.JFrame {
int beli,bayar,tarif;
/**
* Creates new form TiketKretaApi
*/
public TiketKretaApi() {
initComponents();
}
private void cmb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cmb1.getSelectedItem().equals("KA777")){
tfkreta.setText("Mataramaja");
cmb2.removeAllItems();
cmb2.addItem("Pasar Senen - Tegal");
cmb2.addItem("Pasar Senen - Mediun");
}
else if(cmb1.getSelectedItem().equals("KA88")){
tfkreta.setText("Brantas");
cmb2.removeAllItems();
cmb2.addItem("Tanah Abang - Tegal");
cmb2.addItem("Tanah Abang - Mediun");
}
else {
tfkreta.setText("Bengawan");
cmb2.removeAllItems();
cmb2.addItem("Tanah Abang - Kutoraja");
cmb2.addItem("Tanah Abang - Lemayaung");
}
}
private void cmb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void rb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb1.isSelected()){
if(cmb2.getSelectedItem().equals("Pasar Senen - Tegal")){
tarif=30000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Pasar Senen - Mediun")){
tarif=35000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Tegal")){
tarif=40000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Mediun")){
tarif=45000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Kutoraja")){
tarif=50000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Lemayaung")){
tarif=55000;
tftarif.setText(String.valueOf(tarif));
}
}
}
private void rb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb2.isSelected()){
if(cmb2.getSelectedItem().equals("Pasar Senen - Tegal")){
tarif=50000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Pasar Senen - Mediun")){
tarif=55000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Tegal")){
tarif=60000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Mediun")){
tarif=65000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Kutoraja")){
tarif=70000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Lemayaung")){
tarif=75000;
tftarif.setText(String.valueOf(tarif));
}
}
}
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null,"Thank You","Exit",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tfbayar.setText("");
tfbeli.setText("");
tfkreta.setText("");
tfpenumpang.setText("");
tftarif.setText("");
cmb2.removeAllItems();
buttonGroup1.clearSelection();
}
private void tfbayarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void tfbeliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
beli=Integer.parseInt(tfbeli.getText());
bayar = beli * tarif;
tfbayar.setText(String.valueOf(bayar));
}
/**
* @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(TiketKretaApi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TiketKretaApi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TiketKretaApi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TiketKretaApi.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 TiketKretaApi().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btn1;
private javax.swing.JButton btn2;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JComboBox cmb1;
private javax.swing.JComboBox cmb2;
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.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JRadioButton rb1;
private javax.swing.JRadioButton rb2;
private javax.swing.JTextField tfbayar;
private javax.swing.JTextField tfbeli;
private javax.swing.JTextField tfkreta;
private javax.swing.JTextField tfpenumpang;
private javax.swing.JTextField tftarif;
// End of variables declaration
}
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DINDIN
*/
public class TiketKretaApi extends javax.swing.JFrame {
int beli,bayar,tarif;
/**
* Creates new form TiketKretaApi
*/
public TiketKretaApi() {
initComponents();
}
private void cmb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(cmb1.getSelectedItem().equals("KA777")){
tfkreta.setText("Mataramaja");
cmb2.removeAllItems();
cmb2.addItem("Pasar Senen - Tegal");
cmb2.addItem("Pasar Senen - Mediun");
}
else if(cmb1.getSelectedItem().equals("KA88")){
tfkreta.setText("Brantas");
cmb2.removeAllItems();
cmb2.addItem("Tanah Abang - Tegal");
cmb2.addItem("Tanah Abang - Mediun");
}
else {
tfkreta.setText("Bengawan");
cmb2.removeAllItems();
cmb2.addItem("Tanah Abang - Kutoraja");
cmb2.addItem("Tanah Abang - Lemayaung");
}
}
private void cmb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void rb1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb1.isSelected()){
if(cmb2.getSelectedItem().equals("Pasar Senen - Tegal")){
tarif=30000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Pasar Senen - Mediun")){
tarif=35000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Tegal")){
tarif=40000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Mediun")){
tarif=45000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Kutoraja")){
tarif=50000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Lemayaung")){
tarif=55000;
tftarif.setText(String.valueOf(tarif));
}
}
}
private void rb2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb2.isSelected()){
if(cmb2.getSelectedItem().equals("Pasar Senen - Tegal")){
tarif=50000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Pasar Senen - Mediun")){
tarif=55000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Tegal")){
tarif=60000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Mediun")){
tarif=65000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Kutoraja")){
tarif=70000;
tftarif.setText(String.valueOf(tarif));
}
else if(cmb2.getSelectedItem().equals("Tanah Abang - Lemayaung")){
tarif=75000;
tftarif.setText(String.valueOf(tarif));
}
}
}
private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(null,"Thank You","Exit",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tfbayar.setText("");
tfbeli.setText("");
tfkreta.setText("");
tfpenumpang.setText("");
tftarif.setText("");
cmb2.removeAllItems();
buttonGroup1.clearSelection();
}
private void tfbayarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void tfbeliActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
beli=Integer.parseInt(tfbeli.getText());
bayar = beli * tarif;
tfbayar.setText(String.valueOf(bayar));
}
/**
* @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(TiketKretaApi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TiketKretaApi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TiketKretaApi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TiketKretaApi.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 TiketKretaApi().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btn1;
private javax.swing.JButton btn2;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JComboBox cmb1;
private javax.swing.JComboBox cmb2;
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.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JRadioButton rb1;
private javax.swing.JRadioButton rb2;
private javax.swing.JTextField tfbayar;
private javax.swing.JTextField tfbeli;
private javax.swing.JTextField tfkreta;
private javax.swing.JTextField tfpenumpang;
private javax.swing.JTextField tftarif;
// End of variables declaration
}
Tidak ada komentar:
Posting Komentar