import java.awt.*;
import PicturePanel;
import User;

public class Main extends java.applet.Applet
{	
   Panel panel;
   User CurrentUser = new User();
   BorderLayout layMain;

   public void init()
   {
//        User.host = "hemphill215.residence.gatech.edu";
        CurrentUser.loadUser("bleslie");
        setLayout(layMain = new BorderLayout());
	panel = new Panel();
	add("Center",panel);
        LoadLoginManager();

   }

   void LoadLoginManager()
   {
      Image login;
      MediaTracker t = new MediaTracker(this);
      login = getImage(getCodeBase(),"login.gif");
      t.addImage(login,1);
      try t.waitForID(1);
      catch (InterruptedException ie);
      panel = new LoginPanel(login,  this);
      add("Center",panel);
 
   }

   void LoadSplashScreen()
   {
      remove(panel);
 
      Image login;
      MediaTracker t = new MediaTracker(this);
      login = getImage(getCodeBase(),"login.gif");
      t.addImage(login,1);
      try t.waitForID(1);
      catch (InterruptedException ie) return;
 
      Image splash;
      MediaTracker u = new MediaTracker(this);
      splash = getImage(getCodeBase(),"IF-bcheck.gif");
      u.addImage(splash,1);
      try u.waitForID(1);
      catch (InterruptedException ie) return;
 
      panel = new SplashPanel(login, splash);
 
      add("Center",panel);
      paintAll(this.getGraphics());
 
   }



   void LoadCreditCardManager()
   {
   }

   void LoadSavingsManager()
   {
   }   

void LoadTransactionManager(Account account)
{
      remove(panel);
      TransactionPanel panel;
      Image tbg1, tbg2, tbg3;
      MediaTracker t = new MediaTracker(this);
      tbg1 = getImage(getCodeBase(), "IF-bcheck.gif");
      t.addImage(tbg1, 2);
      try t.waitForID(2);
      catch (InterruptedException ie) return;
      tbg2 = getImage(getCodeBase(), "IF-bcheck-bottom.gif");
      t.addImage(tbg2, 3);
      try t.waitForID(3);
      catch (InterruptedException ie) return;
      tbg3 = getImage(getCodeBase(), "TransactionManager-top2.gif");
      t.addImage(tbg2, 3);
      try t.waitForID(3);
      catch (InterruptedException ie) return;
 
      panel = new TransactionPanel(tbg1, tbg2, tbg3, account, this);
 
      add("Center",panel);
 
      repaint();
      paintAll(this.getGraphics());

}

   
   void LoadAccountManager()
   {
      AccountManager panel;
      Image mbg, tbg1, tbg2;
      MediaTracker t = new MediaTracker(this);
      mbg = getImage(getCodeBase(),"If-Open.gif");
      t.addImage(mbg,1);
      try t.waitForID(1);
      catch (InterruptedException ie) return;
      tbg1 = getImage(getCodeBase(), "IF-bcheck.gif");
      t.addImage(tbg1, 2);
      try t.waitForID(2);
      catch (InterruptedException ie) return;
      tbg2 = getImage(getCodeBase(), "IF-bcheck-bottom.gif");
      t.addImage(tbg2, 3);
      try t.waitForID(3);
      catch (InterruptedException ie) return;

      panel = new AccountManager(this, mbg, tbg1, tbg2, CurrentUser);
 
      add("Center",panel);

      repaint();
      paintAll(this.getGraphics());
   }

   void LoadReportManager()
   {
      remove(panel);
      Image leImage;
      CurrentUser.loadUser("bleslie");
      MediaTracker t = new MediaTracker(this);
      leImage = getImage(getCodeBase(),"ReportManager.gif");
      t.addImage(leImage,1);
      try t.waitForID(1);
      catch (InterruptedException ie) ;
      panel = new ChartUI(leImage, CurrentUser); 
      add("Center",panel);
	repaint();
	paintAll(this.getGraphics());
   }

   public boolean mouseUp(Event evt, int x, int y)
   {
      System.out.println(" "+x +" "+ y);
      if ((x > 555) && (x < 572) && (y > 247) && (y < 295))
      {
         LoadAccountManager();
      }  
      if((x > 555) && (x < 572) && (y > 303) && (y < 351))
      {
         LoadSavingsManager();
      }

      if((x > 555) && (x < 572) && (y > 355) && (y < 403))
      {
         LoadCreditCardManager();
      }
     
      if((x > 555) && (x < 572) && (y > 408) && (y < 456))
      {
         LoadReportManager();
      }

      return true;
   }


}


