package interactiveproject.bankaccount;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Timer;

/*
 * 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.
 */
/**
 *
 * @author Ronny
 */
public class MainFrame extends javax.swing.JFrame {

    private int pin = 0;

    //bank notes
    private int notes10 = 0;
    private int notes20 = 0;
    private int notes50 = 0;

    private int value = 0;

    private boolean pinMode = true;

    //link to the students implementation
    private Object studentObject;
    private Class studentClass;

    //booleans to show messages only once
    boolean messageError = false;
    boolean balanceError = false;
    
    private Timer checkTimer = new Timer(500, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateBalance();
        }
    });
    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();

        try {
            studentClass = Class.forName("interactiveproject.bankaccount.Account");
            studentObject = studentClass.newInstance();
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
            System.out.println("Le constructeur Account() n'a pas ete trouve");
        }

        bankNotePanel10.setImage("10euro");
        bankNotePanel20.setImage("20euro");
        bankNotePanel50.setImage("50euro");
        notesPanel.setVisible(false);
        selectionPanel.setVisible(false);
        balancePanel1.setVisible(false);
        updateMessage();
        checkTimer.start();
    }

    public Object getStudentObject() {
        return studentObject;
    }

    public Class getStudentClass() {
        return studentClass;
    }
    public void updateMessage()
    {

        try {
            Method method = studentClass.getMethod("getMessage");
            Object o = method.invoke(studentObject);
            messagePanel.setText((String) o);
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            if(!messageError)
            {
                System.out.println("Aucun message ne peut etre affiche, comme la methode String getMessage n'est pas implementee");
                messageError = true;
            }
        }
        
    }
    public void updateValue() {
        value = 10 * notes10 + 20 * notes20 + 50 * notes50;
        amountLabel.setText("Amount selected: " + String.valueOf(value) + "€");
    }
    
    public void updateBalance()
    {
        try {
            Method method = studentClass.getMethod("getBalance");
            Object o = method.invoke(studentObject);
            balancePanel1.setText("Account Balance: "+String.valueOf((double) o)+"€");
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            if(!balanceError)
            {
                System.out.println("Le credit ne peut pas etre affiche, comme la methode getBalance n'a pas ete implementee");
                balanceError = true;
            }
        }
    }

    public void updateNotes()
    {
        bankNotePanel10.setNotes(notes10);
        bankNotePanel20.setNotes(notes20);
        bankNotePanel50.setNotes(notes50);
    }
    public void updatePin() {
        if (pin != 0) {
            pinLabel.setText(String.valueOf(pin));
        } else {
            pinLabel.setText("");
        }

    }

    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        pinPanel = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        enterButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        pinLabel = new javax.swing.JLabel();
        jButton10 = new javax.swing.JButton();
        screenPanel = new javax.swing.JPanel();
        messagePanel = new javax.swing.JLabel();
        selectionPanel = new javax.swing.JPanel();
        withdrawPanel = new javax.swing.JLabel();
        exitPanel = new javax.swing.JLabel();
        depositPanel = new javax.swing.JLabel();
        notesPanel = new javax.swing.JPanel();
        bankNotePanel20 = new interactiveproject.bankaccount.bankNotePanel();
        bankNotePanel10 = new interactiveproject.bankaccount.bankNotePanel();
        bankNotePanel50 = new interactiveproject.bankaccount.bankNotePanel();
        add20Button = new javax.swing.JButton();
        remove20Button = new javax.swing.JButton();
        add10Button = new javax.swing.JButton();
        remove10Button = new javax.swing.JButton();
        add50Button = new javax.swing.JButton();
        remove50Button = new javax.swing.JButton();
        amountLabel = new javax.swing.JLabel();
        balancePanel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Bank Account");
        setResizable(false);

        pinPanel.setBackground(new java.awt.Color(153, 102, 0));

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

        jButton2.setText("2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("3");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton6.setText("6");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton4.setText("4");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("5");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton9.setText("9");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton7.setText("7");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("8");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        enterButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        enterButton.setText("Enter");
        enterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enterButtonActionPerformed(evt);
            }
        });

        deleteButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        deleteButton.setText("Delete");
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        pinLabel.setBackground(new java.awt.Color(0, 0, 0));
        pinLabel.setForeground(new java.awt.Color(0, 204, 51));
        pinLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        pinLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        pinLabel.setOpaque(true);

        jButton10.setText("0");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pinPanelLayout = new javax.swing.GroupLayout(pinPanel);
        pinPanel.setLayout(pinPanelLayout);
        pinPanelLayout.setHorizontalGroup(
            pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pinPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pinLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(pinPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pinPanelLayout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton3))
                            .addGroup(pinPanelLayout.createSequentialGroup()
                                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton9, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING))))
                        .addGap(12, 12, 12))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pinPanelLayout.createSequentialGroup()
                        .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(pinPanelLayout.createSequentialGroup()
                                .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton10)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(pinPanelLayout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton5)
                                    .addComponent(jButton8)
                                    .addComponent(jButton2))))
                        .addGap(18, 18, 18)
                        .addComponent(enterButton)))
                .addContainerGap())
        );
        pinPanelLayout.setVerticalGroup(
            pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pinPanelLayout.createSequentialGroup()
                .addContainerGap(19, Short.MAX_VALUE)
                .addComponent(pinLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton5)
                    .addComponent(jButton6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(jButton8)
                    .addComponent(jButton9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteButton)
                    .addComponent(enterButton)
                    .addComponent(jButton10))
                .addGap(25, 25, 25))
        );

        screenPanel.setBackground(new java.awt.Color(0, 0, 0));

        messagePanel.setBackground(new java.awt.Color(0, 0, 0));
        messagePanel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        messagePanel.setForeground(new java.awt.Color(255, 255, 0));
        messagePanel.setText("Welcome! Please enter your PIN to begin.");
        messagePanel.setOpaque(true);

        selectionPanel.setOpaque(false);

        withdrawPanel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        withdrawPanel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        withdrawPanel.setText("Withdraw");
        withdrawPanel.setOpaque(true);
        withdrawPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                withdrawPanelMouseClicked(evt);
            }
        });

        exitPanel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        exitPanel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        exitPanel.setText("Exit");
        exitPanel.setOpaque(true);
        exitPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                exitPanelMouseClicked(evt);
            }
        });

        depositPanel.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        depositPanel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        depositPanel.setText("Deposit");
        depositPanel.setOpaque(true);
        depositPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                depositPanelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout selectionPanelLayout = new javax.swing.GroupLayout(selectionPanel);
        selectionPanel.setLayout(selectionPanelLayout);
        selectionPanelLayout.setHorizontalGroup(
            selectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(selectionPanelLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(withdrawPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(depositPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(exitPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        selectionPanelLayout.setVerticalGroup(
            selectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(selectionPanelLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(selectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exitPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(withdrawPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(depositPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout bankNotePanel20Layout = new javax.swing.GroupLayout(bankNotePanel20);
        bankNotePanel20.setLayout(bankNotePanel20Layout);
        bankNotePanel20Layout.setHorizontalGroup(
            bankNotePanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 139, Short.MAX_VALUE)
        );
        bankNotePanel20Layout.setVerticalGroup(
            bankNotePanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 57, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout bankNotePanel10Layout = new javax.swing.GroupLayout(bankNotePanel10);
        bankNotePanel10.setLayout(bankNotePanel10Layout);
        bankNotePanel10Layout.setHorizontalGroup(
            bankNotePanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 139, Short.MAX_VALUE)
        );
        bankNotePanel10Layout.setVerticalGroup(
            bankNotePanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 57, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout bankNotePanel50Layout = new javax.swing.GroupLayout(bankNotePanel50);
        bankNotePanel50.setLayout(bankNotePanel50Layout);
        bankNotePanel50Layout.setHorizontalGroup(
            bankNotePanel50Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 139, Short.MAX_VALUE)
        );
        bankNotePanel50Layout.setVerticalGroup(
            bankNotePanel50Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 57, Short.MAX_VALUE)
        );

        add20Button.setText("+");
        add20Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                add20ButtonActionPerformed(evt);
            }
        });

        remove20Button.setText("-");
        remove20Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remove20ButtonActionPerformed(evt);
            }
        });

        add10Button.setText("+");
        add10Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                add10ButtonActionPerformed(evt);
            }
        });

        remove10Button.setText("-");
        remove10Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remove10ButtonActionPerformed(evt);
            }
        });

        add50Button.setText("+");
        add50Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                add50ButtonActionPerformed(evt);
            }
        });

        remove50Button.setText("-");
        remove50Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                remove50ButtonActionPerformed(evt);
            }
        });

        amountLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout notesPanelLayout = new javax.swing.GroupLayout(notesPanel);
        notesPanel.setLayout(notesPanelLayout);
        notesPanelLayout.setHorizontalGroup(
            notesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(notesPanelLayout.createSequentialGroup()
                .addGap(127, 127, 127)
                .addComponent(remove50Button)
                .addGap(18, 18, 18)
                .addComponent(bankNotePanel50, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(add50Button)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, notesPanelLayout.createSequentialGroup()
                .addComponent(remove10Button)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bankNotePanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(add10Button)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(remove20Button)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bankNotePanel20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(add20Button)
                .addGap(25, 25, 25))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, notesPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(amountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(83, 83, 83))
        );
        notesPanelLayout.setVerticalGroup(
            notesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, notesPanelLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(amountLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(notesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, notesPanelLayout.createSequentialGroup()
                        .addGroup(notesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(remove20Button, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(add10Button, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30))
                    .addGroup(notesPanelLayout.createSequentialGroup()
                        .addGroup(notesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bankNotePanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bankNotePanel20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(notesPanelLayout.createSequentialGroup()
                                .addGap(13, 13, 13)
                                .addComponent(add20Button, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(notesPanelLayout.createSequentialGroup()
                                .addGap(15, 15, 15)
                                .addComponent(remove10Button, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)))
                .addGroup(notesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bankNotePanel50, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(notesPanelLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(add50Button, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(notesPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(remove50Button, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        balancePanel1.setBackground(new java.awt.Color(0, 0, 0));
        balancePanel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        balancePanel1.setForeground(new java.awt.Color(255, 255, 0));
        balancePanel1.setText("Account Balance:");
        balancePanel1.setOpaque(true);

        javax.swing.GroupLayout screenPanelLayout = new javax.swing.GroupLayout(screenPanel);
        screenPanel.setLayout(screenPanelLayout);
        screenPanelLayout.setHorizontalGroup(
            screenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(screenPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(messagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(screenPanelLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(screenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(notesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(selectionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(68, Short.MAX_VALUE))
            .addGroup(screenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(screenPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(balancePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        screenPanelLayout.setVerticalGroup(
            screenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(screenPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(messagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50)
                .addComponent(selectionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(notesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(screenPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(screenPanelLayout.createSequentialGroup()
                    .addGap(53, 53, 53)
                    .addComponent(balancePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(318, Short.MAX_VALUE)))
        );

        jLabel3.setBackground(new java.awt.Color(255, 255, 255));
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interactiveproject/bankaccount/bank logo.png"))); // NOI18N
        jLabel3.setOpaque(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(screenPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pinPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(screenPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pinPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        pin = 10 * pin + 1;
        updatePin();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        pin = 10 * pin + 2;
        updatePin();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        pin = 10 * pin + 3;
        updatePin();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        pin = 10 * pin + 4;
        updatePin();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        pin = 10 * pin + 5;
        updatePin();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        pin = 10 * pin + 6;
        updatePin();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        pin = 10 * pin + 7;
        updatePin();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        pin = 10 * pin + 8;
        updatePin();
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        pin = 10 * pin + 9;
        updatePin();
    }//GEN-LAST:event_jButton9ActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        pin = 0;
        updatePin();
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        pin = 10 * pin + 0;
        updatePin();
    }//GEN-LAST:event_jButton10ActionPerformed

    private void add20ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_add20ButtonActionPerformed
        notes20++;
        bankNotePanel20.setNotes(notes20);
        updateValue();
    }//GEN-LAST:event_add20ButtonActionPerformed

    private void remove20ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove20ButtonActionPerformed
        notes20--;
        notes20 = Math.max(notes20, 0);
        bankNotePanel20.setNotes(notes20);
        updateValue();
    }//GEN-LAST:event_remove20ButtonActionPerformed

    private void add10ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_add10ButtonActionPerformed
        notes10++;
        bankNotePanel10.setNotes(notes10);
        updateValue();
    }//GEN-LAST:event_add10ButtonActionPerformed

    private void remove10ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove10ButtonActionPerformed
        notes10--;
        notes10 = Math.max(notes10, 0);
        bankNotePanel10.setNotes(notes10);
        updateValue();
    }//GEN-LAST:event_remove10ButtonActionPerformed

    private void add50ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_add50ButtonActionPerformed
        notes50++;
        bankNotePanel50.setNotes(notes50);
        updateValue();
    }//GEN-LAST:event_add50ButtonActionPerformed

    private void remove50ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove50ButtonActionPerformed
        notes50--;
        notes50 = Math.max(notes50, 0);
        bankNotePanel50.setNotes(notes50);
        updateValue();
    }//GEN-LAST:event_remove50ButtonActionPerformed

    private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enterButtonActionPerformed

        if (pinMode) {
            Method method = null;
            try {
                method = studentClass.getMethod("isPinValid", int.class);
                Object o = method.invoke(studentObject, pin);
                if ((boolean) o) {
                    notesPanel.setVisible(true);
                    selectionPanel.setVisible(true);
                    balancePanel1.setVisible(true); 
                }
                pin = 0;
                updatePin();
                updateMessage();
                updateBalance();
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                System.out.println("Le code PIN ne peut pas etre verifie, comme la methode boolean isPinValid n'a pas ete implementee.");
            }
        }
    }//GEN-LAST:event_enterButtonActionPerformed

    private void exitPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_exitPanelMouseClicked
        notesPanel.setVisible(false);
        selectionPanel.setVisible(false);
        balancePanel1.setVisible(false);
        pinMode = true;
    }//GEN-LAST:event_exitPanelMouseClicked

    private void withdrawPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_withdrawPanelMouseClicked
        try {
            Method method = studentClass.getMethod("withdraw", double.class);
            Object o = method.invoke(studentObject, (double) value);
            value = 0;
            notes10 = 0;
            notes20 = 0;
            notes50 = 0;
            updateMessage();
            updateValue();
            updateBalance();
            updateNotes();
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            System.out.println("La methode boolean withdraw n'a pas ete implemetee correctement!");
        }
        
    }//GEN-LAST:event_withdrawPanelMouseClicked

    private void depositPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_depositPanelMouseClicked
        try{
            Method method = studentClass.getMethod("deposit", double.class);
            Object o = method.invoke(studentObject, (double) value);
            value = 0;
            notes10 = 0;
            notes20 = 0;
            notes50 = 0;
            updateMessage();
            updateValue();
            updateBalance();
            updateNotes();
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            System.out.println("La methode void deposit n'a pas ete implemetee correctement!");
        }
    }//GEN-LAST:event_depositPanelMouseClicked

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton add10Button;
    private javax.swing.JButton add20Button;
    private javax.swing.JButton add50Button;
    private javax.swing.JLabel amountLabel;
    private javax.swing.JLabel balancePanel1;
    private interactiveproject.bankaccount.bankNotePanel bankNotePanel10;
    private interactiveproject.bankaccount.bankNotePanel bankNotePanel20;
    private interactiveproject.bankaccount.bankNotePanel bankNotePanel50;
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel depositPanel;
    private javax.swing.JButton enterButton;
    private javax.swing.JLabel exitPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel messagePanel;
    private javax.swing.JPanel notesPanel;
    private javax.swing.JLabel pinLabel;
    private javax.swing.JPanel pinPanel;
    private javax.swing.JButton remove10Button;
    private javax.swing.JButton remove20Button;
    private javax.swing.JButton remove50Button;
    private javax.swing.JPanel screenPanel;
    private javax.swing.JPanel selectionPanel;
    private javax.swing.JLabel withdrawPanel;
    // End of variables declaration//GEN-END:variables
}
