//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PIMS: Personal Invstment Management System
//Class : SetAlerts
//This class provides the GUI for the user to see the pertinent alerts
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import java.io.*;
import java.util.*;

public class ShowAlerts extends JFrame implements ActionListener{

	private Alerts AL;
	private String alerts[][];
	private int numAlerts;

	public ShowAlerts(Alerts AL)throws Exception{
		this.AL = AL;
		
		alerts = AL.checkForAlerts();

		//Count the number of alerts
		numAlerts = 0;
		while(alerts[numAlerts][0] != null)numAlerts++;
		
		//Now show the pending alerts
		makeGUI();
	}

	private void makeGUI()throws Exception{

		setSize(400, 200);
		setLocation(120,150);
		setTitle("Pending Alerts");
		setBackground(Color.white);
		Container CP = getContentPane();
		CP.setLayout(new FlowLayout());
		CP.setBackground(Color.white);

		Panel pan1 = new Panel();
		pan1.setLayout(new GridLayout(numAlerts+1, 2));
		Label dt = new Label("Date");
		Label details = new Label("Details");
		pan1.add(dt);
		pan1.add(details);
		for(int i=0;i<numAlerts;++i){
			pan1.add(new Label(alerts[i][0]));
			pan1.add(new Label(alerts[i][1]));
		}

		Panel pan2 = new Panel();
		Button ok = new Button("Ok");
		ok.addActionListener(this);
		pan2.add(ok);

		CP.add(pan1);
		CP.add(pan2);
		setVisible(true);
	}

	public void actionPerformed(ActionEvent ae){

		setVisible(false);
	}
}
