// herbruikbare package

package be.hogent.h17;

import java.awt.*;
import javax.swing.*;

public class H17_BankUI extends JPanel {
	
	protected final static String names[] = { "Klant nr", "Voornaam", "Familienaam", "Balans", "Transactie bedrag" };
	
	protected JLabel labels[];
	protected JTextField fields[];
	protected JButton doTask1, doTask2;
	protected JPanel innerPanelCenter, innerPanelSouth;
	
	protected int size;
	
	public static final int ACCOUNT = 0, FIRSTNAME = 1, LASTNAME = 2, BALANCE = 3, TRANSACTION = 4;
	
	public H17_BankUI(int mySize) {
		
		size = mySize;
		labels = new JLabel[size];
		fields = new JTextField[size];
		
		for (int count = 0; count < labels.length; count++)
			labels[count] = new JLabel(names[count]);
		
		for (int count = 0; count < fields.length; count++)
			fields[count] = new JTextField();
		
		innerPanelCenter = new JPanel();
		innerPanelCenter.setLayout(new GridLayout (size,2));
		
		for (int count = 0; count < size; count++) {
			innerPanelCenter.add(labels[count]);
			innerPanelCenter.add(fields[count]);
		}
		
		doTask1 = new JButton();
		doTask2 = new JButton();
		
		innerPanelSouth = new JPanel();
		innerPanelSouth.add (doTask1);
		innerPanelSouth.add (doTask2);
		
		setLayout(new BorderLayout());
		add (innerPanelCenter,BorderLayout.CENTER);
		add (innerPanelSouth,BorderLayout.SOUTH);
		
		validate();
		
	}
		
	public JButton getDoTask1Button() {
		return doTask1;
	}
		
	public JButton getDoTask2Button() {
		return doTask2;
	}
	
	public JTextField[] getFields() {
		return fields;
	}
	
	public void clearFields() {
		for (int count = 0; count < size; count++)
			fields[count].setText("");
	}
	
	public void setFieldValues(String strings[]) throws IllegalArgumentException {
		if (strings.length != size)
			throw new IllegalArgumentException("There must be " + size + " Strings in the array");
		
		for (int count = 0; count < size; count++)
			fields[count].setText(strings[count]);
	}
	
	public String[] getFieldValues() {
		String values[] = new String[size];
		
		for ( int count = 0; count < size; count++)
			values[count] = fields[count].getText();
		
		return values;
	}
	
}