import java.awt.*;
import java.util.Enumeration;

class CardData extends Panel {
	private TextField name = new TextField(20);
	private TextField number = new TextField(8);
	private TextField item = new TextField(20);
	private TextField amount = new TextField(9);
	private TextField balance = new TextField(9);
	private WideList transactions = new WideList(30);	// if Widelist option implemented
//	private List transactions = new List();			// if Widelist option not implemented

	CardData() {
		super(new BorderLayout());
		Panel data = new Panel(new BorderLayout(10,10));
			Panel labels = new Panel(new GridLayout(5,1));
			Panel fields = new Panel(new GridLayout(5,1));
			labels.add(new Label("Card Holder", Label.RIGHT));
			fields.add(name);
			labels.add(new Label("Card Number", Label.RIGHT));
			fields.add(number);
			labels.add(new Label("Item", Label.RIGHT));
			fields.add(item);
			labels.add(new Label("Amount", Label.RIGHT));
			fields.add(amount);
			balance.setEditable(false);
			labels.add(new Label("Card Balance", Label.RIGHT));
			fields.add(balance);
			transactions.setFont(new Font("Courier", Font.PLAIN, 12));
		data.add("West", labels);
		data.add("East", fields);
		this.add("West", data);
		this.add("Center", transactions);
	}

	void display(Card card) {
		if (card == null)
			card = new Card(" <Not Found>", 999999);

		name.setText(card.getName());
		number.setText(card.getNumber() + "");
		item.setText("");
		amount.setText("");
		balance.setText(card.getBalance() + "");
		
		transactions.removeAll();
		for (Enumeration e=card.getTransactionIterator(); e.hasMoreElements(); ) {
			Transaction t = (Transaction) e.nextElement();
			transactions.addItem(t.toString());
		}
	}

	void clearData() {
		name.setText("");
		number.setText("");
		item.setText("");
		amount.setText("");
		balance.setText("");
		transactions.removeAll();
	}

	/** There is a method in Component, getName, with a different
 	  * semantics, but since it is declared public, we must be public also
	**/

	public String getName() { return name.getText(); }

	int getNumber() { return Integer.parseInt(number.getText()); }

	String getItem() { return item.getText(); }

	double getAmount() { return Double.valueOf(amount.getText()).doubleValue(); }
}

