Selasa, 07 Januari 2020

Program ATM Sederhana Login dan Menu ATM dengan GUI Java Netbeans


  • Deskripsi
Program tersebut ialah program ATM sederhana dimana terdapat sistem login dan sistem database menggunakan database MariaDB Mysql. User dapat melakukan transaksi seperti tarik tunai, melakukan cek saldo dan melakukan transfer.

  • Screenshoot program

Tampilan login ATM




Tampilan menu ATM setelah login



Tampilan menu ATM lainnya



Tampilan tarik tunai


Tampilan transfer 

  • Source Code
 1. code mysql database
-- phpMyAdmin SQL Dump
-- version 4.8.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 07, 2020 at 02:53 PM
-- Server version: 10.1.34-MariaDB
-- PHP Version: 5.6.37

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `atm`
--

-- --------------------------------------------------------

--
-- Table structure for table `menu`
--

CREATE TABLE `menu` (
  `pin` varchar(8) NOT NULL,
  `nama` varchar(100) NOT NULL,
  `saldo` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `menu`
--

INSERT INTO `menu` (`pin`, `nama`, `saldo`) VALUES
('129804', 'Husen', 95200000),
('192021', 'hasan', 5500000);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `menu`
--
ALTER TABLE `menu`
  ADD PRIMARY KEY (`pin`);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


2. koneksi.java

/*
 * 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 bank;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.naming.spi.DirStateFactory.Result;
import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class koneksi {
    private Connection conn;
    private Statement ST;
    private ResultSet RS;
   
    public koneksi (){
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/atm" , "root" ,"");
            ST = (Statement) conn.createStatement();
        } catch (Exception e){
            System.err.println(e);   
        }
    }
   
    public void perbarui(String query){
        try{
                ST.executeUpdate(query);
        }catch(Exception e){
            System.out.println(e);
        }
    }
   
    public String[] pin(){
         ArrayList pin2 = new ArrayList();
        try{
                RS = ST.executeQuery("select pin from menu");
                int i=0;
                while(RS.next()){
                    String a = RS.getString("pin");
                    pin2.add(a);
                }
        }catch (Exception e){
            System.err.println(e);
        }
            String[] pin = new String[pin2.size()];
            pin2.toArray(pin);
        return pin;
    }
   
    public String namaNasabah(String pin){
         String nama = "";
        try{
                RS = ST.executeQuery("select nama from menu where pin='"+pin+"'");
                int i=0;
                while(RS.next()){
                    String a = RS.getString("nama");
                    nama=a;
                }
        }catch (Exception e){
            System.err.println(e);
        }
        return nama;
    }
   
    public void tanya(){
        int ind = JOptionPane.showConfirmDialog(null, "Apakah anda ingin melakukan transaksi lagi?", "info", JOptionPane.YES_NO_OPTION);
        if (ind == JOptionPane.YES_OPTION){
            new tampilanATM().setVisible(true);
        }else{
            System.exit(0);
        }
    }
   
    public int saldo(String pin){
         int saldo =0;
        try{
                RS = ST.executeQuery("select saldo from menu where pin='"+pin+"'");
                int i=0;
                while(RS.next()){
                    String a = RS.getString("saldo");
                    saldo=Integer.parseInt(a);
                }
        }catch (Exception e){
            System.err.println(e);
        }
        return saldo;
    }
}


3. login.java

/*
 * 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 bank;

/**
 *
 * @author Windows7
 */
public class login extends javax.swing.JFrame {

    /**
     * Creates new form login
     */
    public login() {
        initComponents();
    }
    static String pinuser = "";
   
    public void ubahpin(String pin){
        pinuser = pin;
    }
   
    public String ambilpin(){
        return pinuser;
    }

    /**
     * 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();
        jLabel3 = new javax.swing.JLabel();
        pin = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("ATM");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel2.setText("BANK BERSAMA");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Masukkan PIN anda");

        jButton1.setText("Confirm");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(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(142, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(175, 175, 175))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(pin))
                        .addGap(129, 129, 129))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(139, 139, 139))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(161, 161, 161))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(40, 40, 40)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(100, Short.MAX_VALUE))
        );

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        koneksi conec = new koneksi();
        String[] dbpin = conec.pin();
        String pin2 = new String(pin.getPassword());
        System.out.println(dbpin.length);
        int benar = 0;
        for (int i = 0; i < dbpin.length; i++) {
            System.out.println(i+"-"+dbpin[i]);
            if (dbpin[i].equals(pin2)) {
                benar = 1;
                break;
            } else {
                benar = 0;
            }
        }
        if (benar == 1) {
            String nama = conec.namaNasabah(pin2);
            javax.swing.JOptionPane.showMessageDialog(null, "Selamat Datang Sdr "+nama);
            new tampilanATM().setVisible(true);
            this.dispose();
            this.ubahpin(pin2);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "Maff PIN yang anda masukan salah, Silahkan coba lagi");
        }
    }                                       

    /**
     * @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(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(login.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 login().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.JPasswordField pin;
    // End of variables declaration                  
}


4. tampilanATM.java

/*
 * 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 bank;

import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class tampilanATM extends javax.swing.JFrame {

    /**
     * Creates new form menu
     */
    public tampilanATM() {
        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() {

        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        tarik1jt = new javax.swing.JButton();
        tarik1_5jt = new javax.swing.JButton();
        lainnya = new javax.swing.JButton();
        tarik2jt = new javax.swing.JButton();
        logout = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Selamat Datang di ATM BANK BERSAMA");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 30, -1, -1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("MENU UTAMA");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 80, 90, -1));

        tarik1jt.setText("1.000.000");
        tarik1jt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tarik1jtActionPerformed(evt);
            }
        });
        getContentPane().add(tarik1jt, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 120, 100, -1));

        tarik1_5jt.setText("1.500.000");
        tarik1_5jt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tarik1_5jtActionPerformed(evt);
            }
        });
        getContentPane().add(tarik1_5jt, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 200, 100, -1));

        lainnya.setText("lainnya");
        lainnya.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lainnyaActionPerformed(evt);
            }
        });
        getContentPane().add(lainnya, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 200, 100, -1));

        tarik2jt.setText("2.000.000");
        tarik2jt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tarik2jtActionPerformed(evt);
            }
        });
        getContentPane().add(tarik2jt, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 120, 100, -1));

        logout.setText("Logout");
        logout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutActionPerformed(evt);
            }
        });
        getContentPane().add(logout, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 270, -1, -1));

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

    private void tarik1jtActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        koneksi conec = new koneksi();
        String pin =new login().ambilpin();
        int saldo = conec.saldo(pin);
        if(saldo<1000000){
            JOptionPane.showMessageDialog(null, "Maaf saldo anda kurang !\nSaldo anda : "+saldo, null, JOptionPane.WARNING_MESSAGE);
        }else{
            saldo = saldo - 1000000;
            conec.perbarui("UPDATE menu SET saldo="+saldo+" where pin="+pin);
            JOptionPane.showMessageDialog(null, "Transaksi Berhasil!\nSilahkan Ambil Uang Anda", "info", JOptionPane.INFORMATION_MESSAGE);
            conec.tanya();
            this.dispose();
        }
    }                                       

    private void tarik1_5jtActionPerformed(java.awt.event.ActionEvent evt) {                                          
        koneksi conec = new koneksi();
        String pin =new login().ambilpin();
        int saldo = conec.saldo(pin);
        if(saldo<1500000){
            JOptionPane.showMessageDialog(null, "Maaf saldo anda kurang !\nSaldo anda : "+saldo, null, JOptionPane.WARNING_MESSAGE);
        }else{
            saldo = saldo - 1500000;
            conec.perbarui("UPDATE menu SET saldo="+saldo+" where pin="+pin);
            JOptionPane.showMessageDialog(null, "Transaksi Berhasil!\nSilahkan Ambil Uang Anda", "info", JOptionPane.INFORMATION_MESSAGE);
            conec.tanya();
            this.dispose();
        }
    }                                         

    private void lainnyaActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
   
       new lainnya().setVisible(true);
       this.dispose();
    }                                      

    private void tarik2jtActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        //debit
        koneksi conec = new koneksi();
        String pin =new login().ambilpin();
        int saldo = conec.saldo(pin);
        if(saldo<2000000){
            JOptionPane.showMessageDialog(null, "Maaf saldo anda kurang !\nSaldo anda : "+saldo, null, JOptionPane.WARNING_MESSAGE);
        }else{
            saldo = saldo - 2000000;
            conec.perbarui("UPDATE menu SET saldo="+saldo+" where pin="+pin);
            JOptionPane.showMessageDialog(null, "Transaksi Berhasil!\nSilahkan Ambil Uang Anda", "info", JOptionPane.INFORMATION_MESSAGE);
            conec.tanya();
            this.dispose();
        }
    }                                       

    private void logoutActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
        //logout
        javax.swing.JOptionPane.showMessageDialog(null, "Terimakasih Sudah Bertransaksi di ATM BANK BERSAMA");
        new login().setVisible(true);
        this.dispose();
    }                                     

    /**
     * @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(tampilanATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(tampilanATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(tampilanATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(tampilanATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new tampilanATM().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JButton lainnya;
    private javax.swing.JButton logout;
    private javax.swing.JButton tarik1_5jt;
    private javax.swing.JButton tarik1jt;
    private javax.swing.JButton tarik2jt;
    // End of variables declaration                  
}


5. lainnya.java

/*
 * 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 bank;

import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class lainnya extends javax.swing.JFrame {

    /**
     * Creates new form lainnya
     */
    public lainnya() {
        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() {

        P_tunai = new javax.swing.JButton();
        transfer = new javax.swing.JButton();
        ceksaldo = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        kembali = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        P_tunai.setText("PENARIKAN TUNAI");
        P_tunai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                P_tunaiActionPerformed(evt);
            }
        });

        transfer.setText("TRANSFER");
        transfer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                transferActionPerformed(evt);
            }
        });

        ceksaldo.setText("CEK SALDO");
        ceksaldo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ceksaldoActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("MENU UTAMA LAINNYA");

        kembali.setText("Kembali");
        kembali.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kembaliActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(128, 128, 128))
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(kembali, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(P_tunai, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(transfer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 68, Short.MAX_VALUE)
                        .addComponent(ceksaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(40, 40, 40))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(P_tunai)
                    .addComponent(ceksaldo))
                .addGap(70, 70, 70)
                .addComponent(transfer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addComponent(kembali)
                .addContainerGap())
        );

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

    private void kembaliActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        //kembali
        new tampilanATM().setVisible(true);
        this.dispose();
    }                                      

    private void ceksaldoActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        koneksi conec = new koneksi();
        String pin =new login().ambilpin();
        int saldo = conec.saldo(pin);
            JOptionPane.showMessageDialog(null, "Saldo anda : "+saldo, null, JOptionPane.INFORMATION_MESSAGE);
            conec.tanya();
            this.dispose();
    }                                       

    private void P_tunaiActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        new penarikantunai().setVisible(true);
        this.dispose();
    }
 private void transferActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        new transfer().setVisible(true);
        this.dispose();
    }                                       

    /**
     * @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(lainnya.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(lainnya.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(lainnya.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(lainnya.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 lainnya().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    private javax.swing.JButton P_tunai;
    private javax.swing.JButton ceksaldo;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JButton kembali;
    private javax.swing.JButton transfer;
    // End of variables declaration                  
}

6. penarikantunai.java

 /*
 * 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 bank;

import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class penarikantunai extends javax.swing.JFrame {

    /**
     * Creates new form penarikantunai
     */
    public penarikantunai() {
        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() {

        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        angka = new javax.swing.JTextField();
        tarik = new javax.swing.JButton();
        batal = new javax.swing.JButton();

        jTextField1.setText("jTextField1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Masukkan nominal");

        tarik.setText("tarik");
        tarik.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tarikActionPerformed(evt);
            }
        });

        batal.setText("batal");
        batal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batalActionPerformed(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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(angka, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(129, 129, 129))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(97, 97, 97))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(60, 60, 60)
                .addComponent(batal, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 119, Short.MAX_VALUE)
                .addComponent(tarik, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(61, 61, 61))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(76, 76, 76)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(angka, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 80, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tarik)
                    .addComponent(batal))
                .addGap(56, 56, 56))
        );

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

    private void batalActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        koneksi conec = new koneksi();
        conec.tanya();
        this.dispose();
    }
 private void tarikActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
         koneksi conec = new koneksi();
         int nominal = Integer.parseInt(angka.getText());
        String pin =new login().ambilpin();
        int saldo = conec.saldo(pin);
        if(saldo<nominal){
            JOptionPane.showMessageDialog(null, "Maaf saldo anda kurang !\nSaldo anda : "+saldo, null, JOptionPane.WARNING_MESSAGE);
        }else{
            saldo = saldo - nominal;
            conec.perbarui("UPDATE menu SET saldo="+saldo+" where pin="+pin);
            JOptionPane.showMessageDialog(null, "Transaksi Berhasil!\nSilahkan Ambil Uang Anda", "info", JOptionPane.INFORMATION_MESSAGE);
            conec.tanya();
            this.dispose();
        }
    }
 /**
     * @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(penarikantunai.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(penarikantunai.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(penarikantunai.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(penarikantunai.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 penarikantunai().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    private javax.swing.JTextField angka;
    private javax.swing.JButton batal;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton tarik;
    // End of variables declaration                  
}


 7. transfer.java

/*
 * 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 bank;

import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class transfer extends javax.swing.JFrame {

    /**
     * Creates new form transfer
     */
    public transfer() {
        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();
        pin = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        angka = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        batal = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("masukkan pin tujuan");

        pin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pinActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("masukkan nominal");

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

        batal.setText("batal");
        batal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batalActionPerformed(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(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(batal, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pin)
                    .addComponent(angka, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(111, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(66, 66, 66)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(pin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(angka, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 85, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(batal))
                .addGap(42, 42, 42))
        );

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

    private void pinActionPerformed(java.awt.event.ActionEvent evt) {                                   
        // TODO add your handling code here:
    }                                  

    private void batalActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        koneksi conec = new koneksi();
        conec.tanya();
        this.dispose();
    }
 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        koneksi conec = new koneksi();
        String pintrans = pin.getText();
        String[] dbpin = conec.pin();
        int benar = 0;
        for (int i = 0; i < dbpin.length; i++) {
            System.out.println(i+"-"+dbpin[i]);
            if (dbpin[i].equals(pintrans)) {
                benar = 1;
                break;
            } else {
                benar = 0;
            }
        }
if (benar==1){
            int saldotrans = conec.saldo(pintrans);
            String nama = conec.namaNasabah(pintrans);
            int nominal = Integer.parseInt(angka.getText());
            String pin =new login().ambilpin();
            int saldo = conec.saldo(pin);
            int ind = JOptionPane.showConfirmDialog(null, "Anda akan mentransfer sebesar "+nominal+" kepada "+ nama + "\nApakah anda Yakin?", "Info", JOptionPane.YES_NO_OPTION);
            if(ind==JOptionPane.YES_OPTION){
                if(saldo<nominal){
                    JOptionPane.showMessageDialog(null, "Maaf saldo anda kurang !\nSaldo anda : "+saldo, null, JOptionPane.WARNING_MESSAGE);
   }else{
                    saldo = saldo - nominal;
                    saldotrans = saldotrans + nominal;
                    conec.perbarui("UPDATE menu SET saldo="+saldo+" where pin="+pin);
                    conec.perbarui("UPDATE menu SET saldo="+saldotrans+" where pin="+pintrans);
                    JOptionPane.showMessageDialog(null, "Transaksi Berhasil!\nUang telah di transfer ke "+nama, "info", JOptionPane.INFORMATION_MESSAGE);
                    conec.tanya();
                    this.dispose();
                }
            }else{
                //kosong
            }
              
        }else{
            javax.swing.JOptionPane.showMessageDialog(null, "Maff PIN yang anda masukan tidak terdaftar, Silahkan coba lagi");
        }
 }                                      

    /**
     * @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(transfer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(transfer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(transfer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(transfer.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 transfer().setVisible(true);
            }
        });
    }
 // Variables declaration - do not modify                    
    private javax.swing.JTextField angka;
    private javax.swing.JButton batal;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField pin;
    // End of variables declaration                  
}

Tidak ada komentar:

Posting Komentar