import java.awt.*;
import java.awt.event.*;

class CompanyInfo extends Dialog implements ActionListener {
	CardCompany company;
	TextField name = new TextField(20);
	TextField debt = new TextField();
	Button ok = new Button("OK");
	Button cancel = new Button("Cancel");

	CompanyInfo(Frame f) {
		super(f, "Company Information", true);
		
		Panel fields = new Panel(new GridLayout(2,2, 15,10));
			fields.add(new Label("Name" , Label.RIGHT));
			fields.add(name);
			fields.add(new Label("Total Debt", Label.RIGHT));
			debt.setEditable(false);
			fields.add(debt);

		Panel buttons = new Panel(new FlowLayout());
			buttons.add(ok);
			ok.addActionListener(this);
			buttons.add(cancel);
			cancel.addActionListener(this);
			
		this.setLayout(new BorderLayout());
		this.add("North", fields);
		this.add("South", buttons);
		this.pack();
	}

	public void setCompany(CardCompany company) {
		this.company = company;
		name.setText(company.getName());
		debt.setText(Double.toString(company.totalBalance()));
	}

	public void actionPerformed(ActionEvent evt) {
		if (evt.getSource() == ok) {
			company.setName(name.getText());
			setVisible(false);;
		}
	
		if (evt.getSource() == cancel) 
			setVisible(false);
	}
}
